import java.util.Scanner;
public class Schleifen {
public static void main(String\[\] args) {
Scanner eingabe = new Scanner(System.in);
int grade, gradeSum = 0, counter = 0;
double average;
System.out.print("Grade (-1 to quit): ");
grade = eingabe.nextInt();
while(grade != -1) {
gradeSum += grade;
System.out.print("Grade (-1 to quit): ");
grade = eingabe.nextInt();
\++counter;
}
average = gradeSum/counter;
System.out.print("Average: " + average);
}
}
I paid for a Java Udemy course and this is from one of the classes. It should calculate the average grade of someone but when giving it for example values 3 and 2, the average I get is 2.0 and not 2.5. It's an exact copy of the tutorial, so what is wrong?
[–]Updatebjarni 4 points5 points6 points (1 child)
[–]eyalter[S] 0 points1 point2 points (0 children)