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
Nataly [62]
2 years ago
14

Write a Java program that reads two numbers from the console. Based on the example in the textbook, write five methods (min, max

, sum, difference, and product) to calculate and return the appropriate results. For the difference method, use the absolute value method and the round method from the Math class to refine your results to the nearest whole positive integer.
Computers and Technology
2 answers:
Digiron [165]2 years ago
5 0

Answer:

Sample run :

Enter two numbers:

11.75 1.5

The minimum of 11.75 and 1.5 is 1.5

The maximum of 11.75 and 1.5 is 11.75

The sum of 11.75 and 1.5 is 13.25

The difference of 11.75 and 1.5, , rounded to the nearest whole integer, is 10

The product of 11.75 and 1.5 is 17.625

Explanation:

import java.util.Scanner;

public class Reader {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter two numbers: ");

double num1 = scan.nextDouble();

double num2 = scan.nextDouble();

System.out.println("The minimum of " + num1 + " and " + num2 + " is "

+ min(num1, num2));

System.out.println("The maximum of " + num1 + " and " + num2 + " is "

+ max(num1, num2));

System.out.println("The sum of " + num1 + " and " + num2 + " is "

+ sum(num1, num2));

System.out.println("The difference of " + num1 + " and " + num2

+ ", , rounded to the nearest whole integer, is "

+ difference(num1, num2));

System.out.println("The product of " + num1 + " and " + num2 + " is "

+ product(num1, num2));

scan.close();

}

private static double product(double n1, double n2) {

return n1 * n2;

}

private static double sum(double n1, double n2) {

return n1 + n2;

}

// using the absolute value method and the round method from the Math class

// to refine the results to the nearest whole positive integer.

private static int difference(double n1, double n2) {

double diff;

diff = n1 - n2;

diff = Math.abs(diff);

int intDiff = (int) Math.round(diff);

return intDiff;

}

private static double max(double n1, double n2) {

if (n1 > n2) {

return n1;

} else {

return n2;

}

}

static double min(double n1, double n2) {

if (n1 < n2) {

return n1;

} else {

return n2;

}

}

}

makvit [3.9K]2 years ago
4 0

Answer:

import java.util.Scanner;

public class num6 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter first number");

       int a = in.nextInt();

       System.out.println("Enter second number");

       int b = in.nextInt();

       //Calling the methods inside the output statement

       System.out.println("Min is "+min(a,b));

       System.out.println("Max is "+ max(a,b));

       System.out.println("Sum is "+sum(a,b));

       System.out.println("Product is "+product(a,b));

       System.out.println("Absolute difference is "+difference(a,b));

   }

   //Min Method

   static int min(int a, int b){

       if (a<b){

           return a;

       }

       else {

           return b;

       }

   }

   //Max Method

   static int max(int a, int b){

       if (a>b){

           return a;

       }

       else {

           return b;

       }

   }

   //Sum Method

   static int sum(int a, int b){

       return a+b;

   }

   //Diference Method

   static int difference(int a, int b){

       int diff = Math.abs(a-b);

       return diff;

   }

   //Product Method

   static int product(int a, int b){

       int prod = a*b;

       return prod;

   }

}

Explanation:

  • Using Java programming language
  • Use the scanner class to prompt and receive two values from the user (integers a and b)
  • Create the four methods as required (Please see the comments in the code)
  • In the difference method use Math.abs() to get the absolute value of the subtraction ensuring that you get a positive number returned
You might be interested in
What is the cell membrane used for ​
Dima020 [189]

Answer:

The cell membrane gives the cell its structure and regulates the materials that enter and leave the cell. Like a drawbridge intended to protect a castle and keep out enemies, the cell membrane only allows certain molecules to enter or exit. Oxygen, which cells need in order to carry out metabolic functions such as cellular respiration, and carbon dioxide, a byproduct of these functions, can easily enter and exit through the membrane. Water can also freely cross the membrane, although it does so at a slower rate. However, highly charged molecules, like ions, cannot directly pass through, nor can large macro molecules like carbohydrates or amino acids. Instead, these molecules must pass through proteins that are embedded in the membrane. In this way, the cell can control the rate of diffusion of these substances.

<u>Summarize</u>: Function of the Cell Membrane. The cell membrane gives the cell its structure and regulates the materials that enter and leave the cell. Like a drawbridge intended to protect a castle and keep out enemies, the cell membrane only allows certain molecules to enter or exit.

<u><em>I hope its helpful!</em></u>

8 0
3 years ago
Read 2 more answers
2. Statement: "I don't agree with you." Nonverbal gesture: Type of gesture:
Kryger [21]
Have u thought about a verbal gesture js



4 0
3 years ago
A company that hires only American Indians is practicing
Mashutka [201]
What’s the question ?
7 0
3 years ago
Read 2 more answers
Design and implement an algorithm that gets a list of k integar values N1, N2,...Nk as well as a special value SUM. Your algorit
Fittoniya [83]

Answer:

The algorithm is as follows:

1. Start

2. Input List

3. Input Sum

4. For i = 0 to length of list - 1

4.1 num1 = List[i]

5. For j = i to length of list - 1

5.1 num2 = List[j]

6. If SUM = num1 + num2

6.1 Print(num1, num2)

6.2 Break

The algorithm is implemented in python as follows:

def checklist(mylist,SUM):

     for i in range(0, len(mylist)):

           num1 = mylist[i]

                 for j in range(i+1, len(mylist)):

                       num2 = mylist[j]

                       if num1 + num2== SUM:

                             print(num1,num2)

                                   break;

Explanation:

I'll explain the Python code

def checklist(mylist,SUM):

This line iterates from 0 to the length of the the last element of the list

     for i in range(0, len(mylist)):

This line initializes num1 to current element of the list

           num1 = mylist[i]

This line iterates from current element of the list to the last element of the list

                 for j in range(i+1, len(mylist)):

This line initializes num1 to next element of the list

                       num2 = mylist[j]

This line checks for pairs equivalent to SUM

                       if num1 + num2== SUM:

The pair is printed here

                             print(num1,num2)

                                   break;

6 0
3 years ago
An inventory clerk, using a computer terminal, views the following on screen: part number, part description, quantity on hand, q
Sveta_85 [38]

Answer:

The answer is letter D. RECORD

Explanation:

An inventory clerk, using a computer terminal, views the following on screen: part number, part description, quantity on hand, quantity on order, order quantity, and reorder point for a particular inventory item. Collectively, these data make up a____Record______

3 0
3 years ago
Other questions:
  • What is a common source of connection problems with ethernets?
    9·2 answers
  • At the beginning of this month, the balance of Reed's checking account was $692.35. So far this month, he has received a paychec
    13·2 answers
  • Technician A says that the push rod connects to a pivoting component mounted at the top of the cylinder head called the camshaft
    14·2 answers
  • Which of the following is a beneficial reason to extract mineral resources from the earth?
    13·2 answers
  • Which WAN technology is designed to work with a variety of commonly used layer-2 protocols and is sometimes called a layer-2.5 t
    15·1 answer
  • Matching: match each step with its correct sequence number. This question tests whether you know the order in which a CPU perfor
    14·1 answer
  • What does the FixedUpdate loop do? Why do developers use it?
    14·1 answer
  • Help giving points mark BRAINLEST
    5·1 answer
  • I need help ASAP please and thank you!
    6·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!