Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1.A. Write a Java program that uses a Scanner object to read in three n

ID: 3590125 • Letter: Q

Question

Question 1.A. Write a Java program that uses a Scanner object to read in three numbers. Multiply the first number by the second number. Square the second number. Take the square root of the third number. Then print the calculated values, the sum of the three numbers, the largest of the three numbers and the smallest of the three numbers. See the sample below for proper formatting of the output. You should control for the decimal point to two decimal places by using the printf statement (see the end of this assignment for a description). You can assume all three numbers are different and you can use the Math Class.

Sample output:

Provide:

Printout of Properly Formatted Source Code

Example output/test cases (2 test cases different than above that show both cases).

Question 1.B. Write a Java program that uses a Scanner object to read in two numbers and determines the smaller and larger number without using Java's Math Class. The program will print the smaller of the two numbers, the larger of the two numbers OR indicate that the numbers are the same.

Sample output:

//Prints the larger and smaller numbers

Enter two numbers: 22 10

The largest number is 22

The smallest number is 10

//Prints that both numbers are the same

Enter two numbers: 10 10

Both numbers are the same

Provide:

Printout of Properly Formatted Source Code

Example output/test cases (2 test cases different than above that show both cases).

Make sure it is done in Java format.

//Prints the larger and smaller numbers

Enter two numbers: 22 10

The largest number is 22

The smallest number is 10

//Prints that both numbers are the same

Enter two numbers: 10 10

Both numbers are the same

jGRASP exec: java A1_MathClass Enter 3 numbers and then hit enter 6 11 40 The new numbers are 66.00, 121.00, 6.32 The sum of all three numbers is 193.32 The smallest number is 6.32 The largest number is 121.00 ----iGRASP: operation complete.

Explanation / Answer

Queestion 1.A

ThreeNumber.java

import java.util.Scanner;

public class ThreeNumber {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter 3 numbers and then hit enter: ");

double a = scan.nextDouble();

double b = scan.nextDouble();

double c = scan.nextDouble();

a = a * b;

b = b * b;

c = Math.sqrt(c);

System.out.printf("The new numbers are %.2f, %.2f, %.2f ",a,b,c);

System.out.println("The Sum of all three numbers: "+(a + b + c));

System.out.print("The smallest number is: ");

if(a < b && a < c){

System.out.printf("%.2f ",a);

} else if(b < c) {

System.out.printf("%.2f ",b);

} else {

System.out.printf("%.2f ",c);

}

System.out.print("The largest number is: ");

if(a > b && a > c){

System.out.printf("%.2f",a);

} else if(b > c) {

System.out.printf("%.2f",b);

} else {

System.out.printf("%.2f",c);

}

}

}

Output:

Enter 3 numbers and then hit enter:
6 11 40
The new numbers are 66.00, 121.00, 6.32
The Sum of all three numbers: 193.32455532033677
The smallest number is: 6.32
The largest number is: 121.00

Question 1.B

SmallLarge.java

import java.util.Scanner;

public class SmallLarge {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

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

int a = scan.nextInt();

int b = scan.nextInt();

if(a>b) {

System.out.println("The largest number is "+a);

System.out.println("The smallest number is "+b);

} else if(b>a){

System.out.println("The largest number is "+b);

System.out.println("The smallest number is "+a);

} else {

System.out.println("Both numbers are the same");

}

}

}

Output:

Enter two numbers:
5
6
The largest number is 6
The smallest number is 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote