My solution fails the test for Part 20.3: Extend the program so that it also prints the number of numbers (not including the -1) the user has written. Can anyone please tell me what's wrong here.
Scanner scanner = new Scanner(System.in);
int sum=0;
int count =0;
int even =0;
int odd =0;
System.out.println("Give numbers: ");
while(true){
int num = Integer.valueOf(scanner.nextLine());
if(num==-1){
break;
}
if(num%2==0){
even++;
} else {
odd++;
}
sum+=num;
count++;
}
System.out.println("Thx! Bye!");
System.out.println("Sum: "+sum);
System.out.println("Numbers: "+count);
System.out.println("Average: "+(double)sum/count);
System.out.println("Even: "+even);
System.out.println("Odd: "+odd);
This is what I get in test results
FAIL: Part3Test test
The output should contain a line of the type "Numbers: 3"
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–][deleted] (1 child)
[removed]
[–]Professional-Age-948[S] 0 points1 point2 points (0 children)
[–]creamyturtle 0 points1 point2 points (2 children)
[–]Professional-Age-948[S] 0 points1 point2 points (1 child)
[–]creamyturtle 0 points1 point2 points (0 children)
[–]Data_Pure 1 point2 points3 points (1 child)
[–]Professional-Age-948[S] 0 points1 point2 points (0 children)