Ask Question
28 December, 11:53

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:

+5
Answers (1)
  1. 28 December, 14:18
    0
    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
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “java Write a method maxMagnitude () with two integer input parameters that returns the largest magnitude value. Use the method in a program ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers