This Lab is about to use Java Class, the program should be able to display the sum, average, first, last, highest, lowest and total numbers entered. In this program, I use two different loops, while, and if. While loop for the user to enter numbers. If loop for system to determine the number to display.
import java.util.Scanner; public class Numbers { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number = 1; int numcount = 0; double average = 0; int sum = 0; int last = 0; int first = 0; int highest = 0; int lowest = 2147483647; while (number!=0) { System.out.print("Please Enter Your Numbers" + "(Enter 0 to get the result): "); number = input.nextInt(); if(number==0) break; //highest number if(number>=highest){ highest = number; } //lowest number if(number 0){ last = number; } //sum and average sum = number + sum; average = sum / numcount; } System.out.println("Your Sum is: " + sum); System.out.println("Your Average is: " + average); System.out.println("Your Total Numbers Entered: " + numcount); System.out.println("Your Highest Number is: " + highest); System.out.println("Your Lowest Number is: " + lowest); System.out.println("Your First Number: " + first); System.out.println("Your Last Number: " + last); } }