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]
3 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]3 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]3 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
Cách soạn thảo văn bản trên word
pickupchik [31]

Answer:

Did you mean How to edit text on word? There are 2 word, Microsoft Word Office and WordPad. The step I give you below is for both.

Explanation:

Steps to edit text on word

Step-1: Select the text you want to edit.

Step-2: Click on Home Tab.

Step-3: Select the style(s) you want to edit from the Font group

8 0
3 years ago
What source ip address does a router use by default when the traceroute command is issued?
maw [93]

When sending an echo request message, a router will use the IP address of the exit interface as the source IP address.

<h3>What is traceroute IP address?</h3>

Traceroute, also called tracepath or tracert, is a network tool used to determine the “path” packets take from one IP address to another.

It provides the hostname, IP address, and the response time to a ping. Enter the IP address that you want to lookup.

Traceroute ensures each hop on the way to a destination device drops a packet and sends back an ICMP error message.

This means traceroute can measure the duration of time between when the data is sent and when the ICMP message is received back for each hop—giving you the RTT value for each hop.

To learn more about IP address, refer

https://brainly.ph/question/4632300

#SPJ4

4 0
2 years ago
The ___ provide(s) shortcuts to commonly used elements
Genrish500 [490]

The quick access toolbar provides shortcuts to commonly used elements.

The Home Tab brings you to the home page and the File Tab allows you to save the file or print it.

I hope this helps! :)

7 0
3 years ago
Read 2 more answers
Please!! I need help, this is due by tonight!!!
lyudmila [28]

Answer:

sorry if it is too late but I think it is d

Explanation:

4 0
3 years ago
The following images show an image before and after being compressed. Which of the following statements correctly identifies the
Whitepunk [10]

Answer:

B. The image on the right is compressed and the compression is lossy.

Explanation:

The image on the right is a little distorted as compared to the left one. And you will find some black spots all around. However, A, B, and C are mentioned, and hence you will find that the right image is compressed, and since A, B and C are represented in full but a little lossy, we can assume that it is lossy compression. You should know that lossless compression is a type of compression in which there is no loss of the data, and in the case of lossy, there is the loss of the original data.

7 0
3 years ago
Other questions:
  • What do you call the process of translating statements written by a developer? What is the result of this process?
    6·1 answer
  • In which type of attack do you get malicious code in links from seemingly reliable websites?
    14·1 answer
  • If a pedestrian begins to cross my path when i have the right of way
    5·1 answer
  • Which type of graph or chart will you use to show changes in data points?
    5·1 answer
  • Ideally an entity identifier is composed of _____ attribute(s).
    11·1 answer
  • Over the past few years a very definite need has arisen in the electrical trades for:
    15·1 answer
  • Simple geometry can compute the height of an object from the the object's shadow length and shadow angle using the formula: tan(
    8·1 answer
  • A (n) ___ system can help a business alleviate the need for multiple information systems.
    13·1 answer
  • Consider the following static method.
    9·1 answer
  • List at least 5 disadvantages caused by computer viruses?​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!