JAVA CODE Write an application that solicits and inputs three integers from the
ID: 3805199 • Letter: J
Question
JAVA CODE
Write an application that solicits and inputs three integers from the user and then displays the sum, average, product, smallest, and largest of the three numbers. You may use any Java input and output method you want, for example the JOptionPane class or the Scanner class.
You must use only integer arithmetic for your calculations.
Use the numbers 7, 3, and 5, in that order, for your program execution that you will submit. Although your program must be written to handle any three integers in general, these specific values must be used for this program submission, in this order.
Explanation / Answer
IntegerArthimeticTest.java
import java.util.Scanner;
public class IntegerArthimeticTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the first number: ");
int first = scan.nextInt();
System.out.println("Enter the second number: ");
int second = scan.nextInt();
System.out.println("Enter the third number: ");
int third = scan.nextInt();
int sum = first + second + third;
int product = first * second * third;
double average = sum/ (double)3;
int small;
int large;
if(first < second && first < third){
small = first;
}
else if(second < third){
small = second;
}
else{
small = third;
}
if(first > second && first < third){
large = first;
}
else if(second > third){
large = second;
}
else{
large = third;
}
System.out.println("Sum is "+sum);
System.out.println("Product is "+product);
System.out.println("Average is "+average);
System.out.println("Smallest is "+small);
System.out.println("Largest is "+large);
}
}
Output:
Enter the first number:
7
Enter the second number:
3
Enter the third number:
5
Sum is 15
Product is 105
Average is 5.0
Smallest is 3
Largest is 5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.