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
grigory [225]
3 years ago
13

Write a method maxMagnitude() with two integer input parameters that returns the largest magnitude value. Use the method in a pr

ogram 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
Computers and Technology
1 answer:
yawa3891 [41]3 years ago
3 0

Answer:

The program in Java is as follows:

import java.util.*;

import java.lang.Math;

public class Main{

public static int maxMagnitude(int num1, int num2){

    int mag = num2;

    if(Math.abs(num1) > Math.abs(num2)){

        mag = num1;

    }

    return mag;

}

public static void main(String[] args) {

 int num1, num2;

 Scanner input = new Scanner(System.in);

 System.out.print("Enter two integers: ");

 num1 = input.nextInt();

 num2 = input.nextInt();

 System.out.println(maxMagnitude(num1,num2));

}

}

Explanation:

The method begins here

public static int maxMagnitude(int num1, int num2){

This initializes the highest magnitude to num2

    int mag = num2;

If the magnitude of num1 is greater than that of num2

    if(Math.abs(num1) > Math.abs(num2)){

mag is set to num1

        mag = num1;

    }

This returns mag

    return mag;

}

The main  method begins here

public static void main(String[] args) {

This declares num1 and num2 as integer

 int num1, num2;

 Scanner input = new Scanner(System.in);

This prompts the user for two integers

 System.out.print("Enter two integers: ");

This gets input for the first integer

 num1 = input.nextInt();

This gets input for the second integer

 num2 = input.nextInt();

This calls the maxMagnitude method and prints the number with the highest magnitude

 System.out.println(maxMagnitude(num1,num2));

}

You might be interested in
Write a destructor for the CarCounter class that outputs the following. End with newline.
ycow [4]

Answer:

Following are the code to this question:

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

Explanation:

Following are the full program to this question:

#include <iostream>//Defining header file

using namespace std;

class CarCounter //Defining class CarCounter

{

public:

CarCounter();//Defining constructor CarCounter

~CarCounter();//Defining destructor CarCounter

private:

int carCount;//Defining integer variable carCount

};

CarCounter::CarCounter()//declaring constructor  

{

carCount = 0;//assign value in carCount variable

return;//using return keyword

}

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

int main() //Defining main method

{

CarCounter* parkingLot = new CarCounter();//Defining class object parkingLot

delete parkingLot;//

return 0;

}

  • In the given C++ language code, a class "CarCounter" is defined, and inside the class, a "constructor, Destructors, and an integer variable" is defined.  
  • Outside the class, the scope resolution operator is used to define the constructor and assign value "0" in the integer variable.  
  • In the above-given code, the scope resolution operator, to define destructor and inside this cout function is used, which prints a message.  
  • In the main method, the class object is created, which automatically calls its class constructor and destructors.  
7 0
3 years ago
How do you use bold text?
taurus [48]

Answer:

Android: Tap and hold the text you're entering in the text field, then choose Bold, Italic, or More . Tap More to choose Strikethrough or Monospace. iPhone: Tap the text you're entering in the text field > Select or Select All > B_I_U. Then, choose Bold, Italic, Strikethrough, or Monospace.

Explanation:

8 0
3 years ago
Read 2 more answers
What is the likely long-term consequence of an increase in the relative percent of greenhouse gases in Earth’s atmosphere?
NemiM [27]

Answer:

Earth's average temperature will increase.

Explanation:

5 0
3 years ago
The use of technological advances in agriculture to increase harvests
BigorU [14]
Tractors,water works, plows, water in general
3 0
3 years ago
What do secondary sources rely on for their analysis of events?
MariettaO [177]

Secondary sources are defined as <u>a form of document that includes information from another source to analyze an issue. </u>

When a researcher or writer wishes to cite a secondary source, it means they are using information from a primary source that is presented in another document which has cited it, <em>instead</em> of directly referring to the primary source.

Thus, it can be said that the best answer for the question above is (D) primary sources only, since secondary sources use this when analyzing the problem presented in their document.

7 0
2 years ago
Read 2 more answers
Other questions:
  • In which setting would you be least likely to find a full-time A/V technician?
    5·2 answers
  • Human factors is the study of:
    5·1 answer
  • The type of database that is connected by a company's local area networks is a(n:
    11·1 answer
  • What is a column in a table
    10·2 answers
  • What are candid shots? what are posed shots?
    13·1 answer
  • PLZ ANSWER THESE QUESTIONS FOR 30 POINTS AND BRAINLIEST!
    9·1 answer
  • Please help me. Adnan also wants to add a photograph of a bridge. It is on another PowerPoint presentation that is open in a dif
    11·1 answer
  • Why do designers of smartphones hide computer processing details from
    14·2 answers
  • Which directory stores the cron configuration file?.
    8·1 answer
  • What are the two protocols used most often with iot devices? (select two. )
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!