On my code, it says that there are 2 mistakes and I can't fix them.
Here is my code:
import java.util.Scanner;
public class Exercise4_1M
{
public static void main(String[] args)
{
int countPositive = 0; int countNegative = 0;
int count = 0; int total = 0;
Scanner input = new Scanner(System.in);
System.out.print(
"Enter an integer, the input ends if it is 0: ");
int num = input.nextInt();
while (num != 0) {
if (num > 0)
countPositive++;
else if (num < 0) {
countNegative++;
}
total += num;
count++;
num = input.nextInt();
}
if (count == 0) {
System.out.println("No numbers were entered except 0");
} else {
System.out.println("The number of positives is " + countPositive);
System.out.println("The number of negatives is " + countNegative);
System.out.println("The total is " + total);
System.out.println("Average is " + total * 1.0D / count);
}
}
}
And this is error log 1:
You got this one wrong test case 2
First Difference Occurs at: byte 119, line 3
On Line 3 its column 15
Line 3 Wrong: The total is 1533672726
Line 3 Right: The total is 10123607318
sdiff side by side difference your output versus solution....
Enter an integer, the input ends if it is 0: The number of po Enter an integer, the input ends if it is 0: The number of po
The number of negatives is 2 The number of negatives is 2
The total is 1533672726 | The total is 10123607318
Average is 8.071961715789473E7 | Average is 532,821,437.79
Octal Dump Difference
0000160 l i s 1 5 3 3 6 7 2 7 | 0000160 l i s 1 0 1 2 3 6 0 7
0000200 A v e r a g e i s 8 . | 0000200 \n A v e r a g e i s 5
Octal Dump Your output...
0000000 E n t e r a n i n t e g e r
0000020 , t h e i n p u t e n d s
0000040 i f i t i s 0 : T h e
0000060 n u m b e r o f p o s i t
0000100 i v e s i s 1 7 \n T h e n
0000120 u m b e r o f n e g a t i v
0000140 e s i s 2 \n T h e t o t a
0000160 l i s 1 5 3 3 6 7 2 7 2 6 \n
0000200 A v e r a g e i s 8 . 0 7 1
0000220 9 6 1 7 1 5 7 8 9 4 7 3 E 7 \n
0000237
Octal Dump Solution..
0000000 E n t e r a n i n t e g e r
0000020 , t h e i n p u t e n d s
0000040 i f i t i s 0 : T h e
0000060 n u m b e r o f p o s i t
0000100 i v e s i s 1 7 \n T h e n
0000120 u m b e r o f n e g a t i v
0000140 e s i s 2 \n T h e t o t a
0000160 l i s 1 0 1 2 3 6 0 7 3 1 8
0000200 \n A v e r a g e i s 5 3 2 ,
0000220 8 2 1 , 4 3 7 . 7 9 \n
0000233
Help On Intpreting Output Better luck next time!
And here is error log 2:
First Difference Occurs at: byte 140, line 4
On Line 4 its column 16
Line 4 Wrong: Average is -124975.0
Line 4 Right: Average is -124,975.00
sdiff side by side difference your output versus solution....
Enter an integer, the input ends if it is 0: The number of po Enter an integer, the input ends if it is 0: The number of po
The number of negatives is 5 The number of negatives is 5
The total is -999800 The total is -999800
Average is -124975.0 | Average is -124,975.00
Octal Dump Difference
0000200 a g e i s - 1 2 4 9 7 | 0000200 a g e i s - 1 2 4 , 9
0000220 \n | 0000220 0 0 \n
Octal Dump Your output...
0000000 E n t e r a n i n t e g e r
0000020 , t h e i n p u t e n d s
0000040 i f i t i s 0 : T h e
0000060 n u m b e r o f p o s i t
0000100 i v e s i s 3 \n T h e n u
0000120 m b e r o f n e g a t i v e
0000140 s i s 5 \n T h e t o t a l
0000160 i s - 9 9 9 8 0 0 \n A v e r
0000200 a g e i s - 1 2 4 9 7 5 . 0
0000220 \n
0000221
Octal Dump Solution..
0000000 E n t e r a n i n t e g e r
0000020 , t h e i n p u t e n d s
0000040 i f i t i s 0 : T h e
0000060 n u m b e r o f p o s i t
0000100 i v e s i s 3 \n T h e n u
0000120 m b e r o f n e g a t i v e
0000140 s i s 5 \n T h e t o t a l
0000160 i s - 9 9 9 8 0 0 \n A v e r
0000200 a g e i s - 1 2 4 , 9 7 5 .
0000220 0 0 \n
0000223
Help On Intpreting Output Better luck next time!
I am not sure how to fix this, the code seems right to me.