Description: This program will first ask to enter 1 to execute or 2 to exit, then as you entering number, it will find the first number entered, last number entered, how much number you entered, lowest and highest two numbers, the sum of all numbers and the average.
import java.util.Scanner;
public class lab1 {
public static void main(String[] args){
Scanner input = new Scanner( System.in );
int Inputnum=0, num=0, count=0;
double firstnum = 0, lastnum = 0, min = 0, min2 = 0, max = 0, max2 = 0, sum = 0;
System.out.println(“Press 1 to enter a number”);
System.out.println(“Press 2 to exit the program”);
num = input.nextInt();
if(num==1){
while (num==1){
System.out.print(“Enter a number: “);
Inputnum = input.nextInt();
count++;
sum += Inputnum;
lastnum = Inputnum;
if (Inputnum > max){
max2 = max;
max = Inputnum;
}
else if ( Inputnum > max2){
max2 = Inputnum;
}
if (Inputnum < min) {
min2 = min;
min = Inputnum;
}
else if (Inputnum < min2){
min2 = Inputnum;
}
if ( count ==1 ){
max = Inputnum;
max2 = Inputnum;
min = Inputnum;
min2 = Inputnum;
firstnum = Inputnum;
}
else
System.out.println(“First Number: ” +firstnum);
System.out.println(“Last Number: ” +lastnum);
System.out.println(“Total Number Enter: ” +count);
System.out.println(“Minimum: ” +min);
System.out.println(“Second Minium: ” +min2);
System.out.println(“Maximum: ” +max);
System.out.println(“Second Maximum: ” +max2);
System.out.println(“Sum: ” +sum);
System.out.println(“Average: ” +sum/count);
}
}
else
System.out.println(“The program will now exit”);
}
}