java Write a method maxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the method in a program that takes two integer inputs, and outputs the largest magnitude value. Ex: If the inputs are: 5 7 the method returns: 7 Ex: If the inputs are:

Respuesta :

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;

}

}

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