The reason you are entering more then 5 number is because the while loop will go until someone enters a number<1. Instead the while loop should check if numamount < 5. Then have an if statement check if the entered number<1.
public static void main(String[] args) { // TODO code application logic here //Create Scanner Scanner input = new Scanner(System.in); int number = 0, sum = 0, numamount = 0; // You can change the variable names. while(numamount < 5) { // Begin while statement System.out.println("Enter a number that is positive or zero: "); // Get the next number number = input.nextInt(); if (number < 0){ System.out.println("you have Entered an invalid number, please enter again: "); number = input.nextInt(); } sum = sum+number; // Get the sum so far. numamount++; // Get the number amount so far. } // End while statement. double average = sum/numamount; //Get the average. System.out.println("You have entered " + numamount + " numbers"); // Output amount of numbers System.out.println("Total of the numbers you entered is " + sum); // Output sum of numbers System.out.println("Average of the numbers is " + average); // Output average of numbers. }