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
Pseudo code for rolling a dice
iogann1982 [59]

Answer:

Explanation:

In this exercise, you will roll a pair of dice until the numbers add up to a given number. You can assume that the given number is 2, 3, 6, or 12. Using pseudocode, write an algorithm that returns the number of times the dice is rolled to achieve this number.

3 0
3 years ago
If an OS is using paging with offsets needing 12 bits, give the offset (in decimal or hexadecimal) to: the third word on a page
Mariulka [41]

Answer:

Explanation:

If an OS is using paging with offsets needing 12 bits, give the offset (in decimal or hexadecimal) to: the third word on a page the last word on a page.

7 0
3 years ago
Name two features that would be useful to potential customers
Dmitry [639]

Answer:

  1. How your business is unique
  2. A clear sense of what your company offers

Explanation:

Respond the subject "Who are you and What your business represents?" as interestingly and compellingly as feasible. This involves recording administration bios that state your expertise, times of struggle and various different qualities or details that may make you special from others.

"It's unbelievable how many businesses you visit and you're unsure something the organization offers". Execute it a superiority on your homepage to present at least comprehensive information regarding your outcomes and/or co-operation.

6 0
3 years ago
What is Tesla BEST know for designing this? ANSWER
Aleonysh [2.5K]

Answer:

  1. tesla coils
  2. tesla
  3. edison
  4. x ray
  5. slinky
  6. time travel
  7. he spent it
  8. blue tooth

Explanation:

3 0
3 years ago
What is the extension of excel worksheet​
muminat

Answer:

Excel file formats

Format Extension

Excel Workbook .xlsx

Excel Macro-Enabled Workbook (code) .xlsm

Excel Binary Workbook .xlsb

Template .xltx

7 0
2 years ago
Other questions:
  • Somebody who is good at this stuff, please halp meh ;-;
    6·1 answer
  • What did basic elements of music look like in the Twentieth Century period?
    6·1 answer
  • According to a recent study, more than 75 percent of teens between the ages of twelve and seventeen in the United States have a
    11·2 answers
  • Lonnie has several workbooks that contain financial and sales data. He needs to ensure that if the data in a single cell in one
    5·1 answer
  • Identify any eight new programming languages and classify them based on their functionality.
    14·2 answers
  • What does "CPU" stand for?
    15·2 answers
  • Specific keys that each finger is responsible for typing is called A. ergonomics B. Touch typing C. Key reaches D. Posture
    8·1 answer
  • What is a simulation?
    5·2 answers
  • ARGENT !!20 POINTS <br> А ________ translates commands from a computer to draw lines on paper.
    10·2 answers
  • Retype the below code. Fix the indentation as necessary to make the program work.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!