Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter two numbers: ");
int number1 = input.nextInt();
int number2 = input.nextInt();
System.out.println("Max magnitude is: " + maxMagnitude(number1, number2));
}
public static int maxMagnitude(int number1, int number2){
number1 = Math.abs(number1);
number2 = Math.abs(number2);
if(number1 >= number2)
return number1;
else
return number2;
}
}
Step-by-step explanation:
In the function:
- Get the absolute value of the numbers to compare their magnitude
- Check which one is greater
In the main:
- Ask the user for the inputs
- Call the function, and print the result