I don't understand where my mistake is. I'm only trying to calculate the average of the inputted numbers. If 0 is the input,it's not calculate to the total of the input numbers.
import java.util.Scanner;
public class AverageOfNumbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double average=0.0;
int nrofnumbers=0;
int sum=0;
while(true){
System.out.println("Give a number: ");
int input = Integer.valueOf(scanner.nextLine());
if(input == 0){
break;
}else{
sum = sum+input;
nrofnumbers=nrofnumbers + 1;
}
}
average = sum/nrofnumbers;
System.out.println("Average of the numbers: "+average);
}
}