Advertisement
prem

Untitled

Oct 23rd, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class InputLoop
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8. int number=0;
  9. System.out.print("Enter an integer or Q to quit: ");
  10. boolean two = false;
  11. while (in.hasNextInt())
  12. {
  13. number = in.nextInt();
  14. System.out.println(number);
  15. if (number == 2)
  16. {
  17. two = true;
  18. }
  19. System.out.print("Enter an integer or Q to quit: ");
  20. }
  21. if (two = true)
  22. {
  23. System.out.println("yes");
  24. }
  25. else
  26. {
  27. System.out.println("no");
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement