012-002-007

Static Method Utility

Medium

Problem Description

static method Utility

In this problem, you will create a program that implements static methods (square, max, isEven) in a MathHelper class, reads values from Scanner, calls them directly by class name without creating instances, and displays the results to standard output.

Learning Objective: Understand how to design utility classes using static methods that can be called without creating instances

Overview

Create a utility class MathHelper with static methods for mathematical calculations that can be called directly without creating instances. In the Main class, read values from standard input and pass them to each method.

Specifications

MathHelper class

  • Define public static int square(int n) that returns the square of the argument
  • Define public static int max(int a, int b) that returns the larger of two arguments
  • Define public static boolean isEven(int n) that returns true for even numbers, false for odd

Main class

  1. Read integer n from standard input and print the result of MathHelper.square(n) in the format "Square of n: result"
  2. Read integers a and b from standard input and print the result of MathHelper.max(a, b) in the format "Max: result"
  3. Read integer x from standard input and print the result of MathHelper.isEven(x) in the format "x is even: result"
  4. Read integer y from standard input and print the result of MathHelper.isEven(y) in the format "y is even: result"

Input Format

n
a b
x
y

Output Format

Square of n: result
Max: result
x is even: result
y is even: result

Sample Input/Output

Input:

5
10 20
7
4

Output:

Square of 5: 25
Max: 20
7 is even: false
4 is even: true

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up