Complete the following program skeleton for the program Exam1A given below. This
ID: 3795507 • Letter: C
Question
Complete the following program skeleton for the program Exam1A given below. This program should ask the user to enter an integer, and continue to prompt for numbers until the user a negative number. The program should then report the value of the largest and smallest non-numbers entered, as well as the sum of all of the non-negative numbers entered Make sure your code produces the same output as that given in the transcript below. You should get the input using the Scanner method extent(). See the last page of the exam for reminders of what this Scanner method docs. Here is a sample transcript of how the program should work. Input typed by the user is indicated by bold text: Enter a number: 7 Enter a number: 2 Enter a number: 6 Enter a number: -1 The largest value is: 7 The smallest value is: 2 The total is: 15 import javas. util. Scanner; public class Exam1A {public static void main(String[] args){Scanner in = new Scanner (System.in);//your code goes hereExplanation / Answer
Exam1A.java:
import java.util.Scanner;
public class Exam1A {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.print("Enter a number: ");
int n=in.nextInt();
int min,max,sum;
if(n>=0){
//This block is executed when first number entered is non-negative
min=n;max=n;sum=n;
while(true){
//User is asked for numbers, until a negative number is entered
System.out.print("Enter a number: ");
n=in.nextInt();
if(n<0)
break;
else{
sum+=n;
if(n>max)
max=n;
else if(n<min)
min=n;
}
}
System.out.println("The largest value is: "+max);
System.out.println("The smallest value is: "+min);
System.out.println("The total is: "+sum);
}
else{
//Else-block is executed when first number entered is negative
System.out.println("You didn't enter any non-negative integer");
}
}
}
Sample Run 1:
Enter a number: 5
Enter a number: 9
Enter a number: 0
Enter a number: -1
The largest value is: 9
The smallest value is: 0
The total is: 14
Sample Run 2:
Enter a number: -9
You didn't enter any non-negative integer
Sample Run 3:
Enter a number: 7
Enter a number: 2
Enter a number: 6
Enter a number: -1
The largest value is: 7
The smallest value is: 2
The total is: 15