1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
makkiz [27]
4 years ago
13

Max magnitude 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: -8 -2 the method returns: -8 Note: The method does not just return the largest value, which for -8 -2 would be -2. Though not necessary, you may use the absolute-value built-in math method. Your program must define and call a method: public static int maxMagnitude(int userVal1, int userVal2)
Computers and Technology
1 answer:
Ira Lisetskai [31]4 years ago
8 0

Answer:

The java program is as follows.

import java.lang.*;

public class Numbers

{

   //variables to hold two numbers

   static int num1=-8, num2=-2;

   //method to return integer with higher magnitude

   public static int maxMagnitude(int userVal1, int userVal2)

   {

       if(Math.abs(userVal1) > Math.abs(userVal2))

           return userVal1;

       else    

           return userVal2;

   }

public static void main(String[] args) {

    int max = maxMagnitude(num1, num2);

 System.out.println("The number with higher magnitude among "+num1+ " and "+num2+ " is "+max);

}

}

OUTPUT

The number with higher magnitude among -8 and -2 is -8

Explanation:

1. Two integer variables are declared to hold the two numbers. The variables are declared at class level (outside main()) and declared static.

2. The variables are initialized with any random value.

3. The method, maxMagnitude(), takes the two integer parameters and returns the number with higher magnitude. Hence, return type of the method is int.

public static int maxMagnitude(int userVal1, int userVal2)

4. This method finds the number with higher magnitude using the Math.abs() method inside if-else statement.

               if(Math.abs(userVal1) > Math.abs(userVal2))

                   return userVal1;

        else    

                   return userVal2;

5. Inside main(), the method, maxMagnitude(), is called. This method takes the two variables as input parameters.

6. The integer returned by the method, maxMagnitude() is assigned to a local integer variable, max, as shown.

      int max = maxMagnitude(num1, num2);

7. The result is displayed to the user as shown.

System.out.println("The number with higher magnitude among "+num1+ " and "+num2+ " is "+max);

8. The class variables and the method, maxMagnitude(), are declared static so that they can be used and called inside main().

9. The variable, max, is called local variable since it can be used only within the main() where it is declared. It is not declared static.

10. The class is declared public since it has the main() method and execution begins with main().

11. The program is saved with the same name as the name of the public class having main(). In this case, the program is saved as Numbers.java.

12. No user input is taken for the two input parameter values. The static variables can be assigned any integer value and the program can be tested accordingly.

You might be interested in
Please helpppp me!! thank youuu :)
Usimov [2.4K]

Answer:

3?

Explanation:

3 0
3 years ago
Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code? String element = "red"; f
maksim [4K]

Answer:

The output of the given code as follows:

<u>Output: </u>

{"red", "green"}

Explanation:

  • In the given code a list is defined, which contains three elements, which are "red, red, and green". In the next step, a string variable "element" is initialized with a value that is "red".
  • Then a for loop is declared, that counts list size, and inside the loop and if block is declared, that compares the value list with element variable then it removes from the list.  

8 0
3 years ago
Anyone know how to translate this 1100111111110100000110 pls n ty!4!:$;
marysya [2.9K]

Answer:

1100111111110100000110 = �

Binary -> UTF-16

3,407,110 in decimal form

Additionally, it also translates to the color green in hexadecimal.

Not really sure what you are trying to translate this in to though.

7 0
3 years ago
Read 2 more answers
By default, headers and footers apply to
AleksAgata [21]
Hold up I know he answer
6 0
3 years ago
I'm in middle school but when I singed in I accidentally put high school, how can I change that?
Pani-rosa [81]
Go to edit profile then go to preferences and select school level

8 0
3 years ago
Read 2 more answers
Other questions:
  • Consider the following page reference string:
    12·1 answer
  • How can people make sure they are using credit cards responsibly
    14·2 answers
  • How to help it automation with python professional certificate?
    10·1 answer
  • In Online Data Extraction data is extracteddirectly from the ------ system itself.o Hosto Destinationo Sourceo Terminal
    15·1 answer
  • tls Explain in your own words how, by applying both asymmetric and symmetric encryption, your browser uses TLS to protect the pr
    8·1 answer
  • OTATAYAYYAYYA HAVE A NICE DAY BEAUTIFUL PEOEOEPOPEPELELELEEL
    5·2 answers
  • A.
    14·1 answer
  • What do u think a creative app must have? <br><br> Please answer the question ASAP!!
    5·1 answer
  • Can someone answer this for me will award brainliest lol
    11·2 answers
  • Configuring a firewall to ignore all incoming packets that request access to a specific port is known as ____.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!