Guessing game code


SUBMITTED BY: Guest

DATE: Jan. 2, 2014, 10:40 p.m.

FORMAT: Java

SIZE: 863 Bytes

HITS: 1036

  1. import java.util.Scanner;
  2. public class Main
  3. {
  4. public static void main(String[] args)
  5. {
  6. Scanner scan = new Scanner (System.in);
  7. int enteredNum;
  8. enteredNum = 0;
  9. int[] countArray;
  10. countArray = new int[51];
  11. boolean SENTINEL = false;
  12. System.out.println("Enter an integer between 0 and 50 (enter '99' to quit): ");
  13. while (enteredNum != 99)
  14. {
  15. enteredNum = scan.nextInt();
  16. if (enteredNum < countArray.length && enteredNum >= 0 && enteredNum <= 50)
  17. {
  18. countArray[enteredNum]++;
  19. }
  20. }
  21. for(int count = 0; countArray[count] >= 0; count++)
  22. {
  23. if (countArray[count] != 0)
  24. {
  25. System.out.println("Array slot " + count + ":" + countArray[count]);
  26. }
  27. }
  28. }
  29. }

comments powered by Disqus