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
i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
nekit [7.7K]

Make sure you check your spam folder. If you don't receive an email within the next 2 hours, try contacting them at this link: brainly.com/app/contact

Good luck

7 0
2 years ago
Can someone pls explain this question??
tatuchka [14]

THE ANSWER IS BABABOOEY

6 1
3 years ago
Explain the difference between undecidable problems and unreasonable time algorithms. Be specific.
ddd [48]

One for which no algorithm can ever be written to find the solution is an unsolvable problem. An undecidable problem is one for which no algorithm can ever be written that will always provide any input value with a correct true/false option.

6 0
2 years ago
Suppose that outFileis an ofstreamvariable and output is to be stored in the file outputData.out. Which of the following stateme
BlackZzzverrR [31]

Answer:

Option b outFile.open("outputData.out");

Explanation:

In C++, there are several classes given to handle output and input of characters to or from files. They are:

  • ofstream that write on files
  • ifstream that read from files

We can use an object of ofstream to hold the contents that we wish to output to an external file. The general syntax is as follows:

           ofstream_obj.open(file_name)

This will create a file with a specific file name and it possesses all the contents from the obstream_obj.

5 0
2 years ago
Which business case is better solved by Artificial intelligence than conventional programming?<br>​
skad [1K]

Answer:

Predicting characteristics of high-value customers is the business case that better solved by Artificial intelligence than conventional programming.

Explanation:

Many corporations and businesses predict CLVs only by resembling at the total monetary expense of sales, without recognition circumstances. For instance, a customer who executes one big order might be less worthwhile than another consumer who purchases multiple occasions, but in more diminutive amounts.

4 0
2 years ago
Other questions:
  • Assign to avg_owls the average owls per zoo. Print avg_owls as an integer. Sample output for inputs: 1 2 4 3
    7·1 answer
  • In UNIX, how do I set the permissions on MyProgram.py to: rwx---r-x?
    7·1 answer
  • New Jersey and New York have the highest state taxes in the United States. They also have high ratios of people moving out compa
    13·1 answer
  • What is the output of 1101 x 10 == 11000 + 10?
    12·1 answer
  • Do you have to make a account of Windows 10?
    12·1 answer
  • , 13 dB correspond to a power ratio of ....?
    14·1 answer
  • Qr code is more developed than barcode​
    11·1 answer
  • a bus is full of passengers. if you count them by either twos, threes, or fives, there is one left. if you count them by seven t
    10·1 answer
  • Rita tried unsuccessfully to open a PDF file attachment in her Inbox by double-clicking the attachment in the Reading Pane. What
    8·1 answer
  • PLEASE ANSWER! I NEED IN 30 MIN.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!