fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner x = new Scanner(System.in);
  13. int num = 0;
  14. int odd = 0, count = 0, even = 0;
  15.  
  16. System.out.print("Enter any number to continue. Enter 0 to stop.");
  17. num = x.nextInt();
  18.  
  19. while (num != 0) {
  20. count ++;
  21. if (num % 2 == 0) {
  22. even ++;
  23. } else {
  24. odd ++;
  25. }
  26. num = x.nextInt();
  27. }
  28. // count++ because in your output 0 is counted as number entered but not as even number
  29. System.out.printf("You entered %d numbers\n",++count);
  30. System.out.printf("You entered %d even numbers\n",even);
  31. System.out.printf("You entered %d odd numbers\n",odd);
  32. }
  33. }
Success #stdin #stdout 0.17s 321344KB
stdin
12
11
5
6
1
0
stdout
Enter any number to continue. Enter 0 to stop.You entered 6 numbers
You entered 2 even numbers
You entered 3 odd numbers