This lab took a little time to figure out but with the help of some classmates figured it out. it took a little time to figure out how to let the program allow the user to only choose the number one. the calculations were easy but the code itself too a little time.This program allows you to chose and input a set of number, then displays the first and last numbers as well as show you how many numbers you entered, then it chooses the two lowest and two highest numbers, after that it adds all the numbers and finds the average of these numbers which is all displayed.
package Lab1; import java.util.Scanner; public class Lab1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int count = 1; int number = 0; int numbers; int firstnum = 0; int sum = 0; int average = 0; int choice; System.out.println("Please choose 1 to enter a number or any other number to exit: "); choice = input.nextInt(); if (choice != 1) { System.exit(0); } System.out.println("Please enter the amount of numbers you will be entering: "); numbers = input.nextInt(); System.out.println("Please enter the first number: "); int number1 = input.nextInt(); int minimum1 = number1; int minimum2 = number1; int maximum1 = number1; int maximum2 = number1; do if (choice == 1) { System.out.println("Please enter a number: "); number = input.nextInt(); // Minimum two numbers if (number <= minimum1) { minimum2 = minimum1; minimum1 = number; } else if (number = maximum1) { maximum2 = maximum1; maximum1 = number; } else if (number > maximum2) { maximum2 = number; } else if (maximum1 == maximum2) { maximum2 = number; } // The first number if (count == 1) { firstnum = number1; } // Sum sum += number; // The average of numbers average = sum / count; count++; } while (count < numbers); // The sum of numbers sum = sum + number1; // The average of numbers average = sum / count; System.out.printf("The first number is: %d\n", firstnum); System.out.printf("The last number is: %d\n", number); System.out.printf("Count of number entered: %d\n", count); System.out.println("The two smallest numbers are " + minimum1 + " and " + minimum2); System.out.println("The two highest numbers are " + maximum1 + " and " + maximum2); System.out.printf("The average of your numbers is: %d\n", average); System.out.printf("The total sum of your numbers is: %d\n", sum); } }