Advertisement
prem

Untitled

Oct 23rd, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 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. boolean max = false;
  12. boolean secondmax=false;
  13. int oddsum = 0;
  14. while (in.hasNextInt())
  15. {
  16. number = in.nextInt();
  17.  
  18. if (number == 2)
  19. {
  20. two = true;
  21. }
  22. if (number % 2 != 0)
  23. {
  24. oddsum = oddsum + number;
  25. }
  26. System.out.print("Enter an integer or Q to quit: ");
  27. }
  28. System.out.println(oddsum);
  29. if (two)
  30. {
  31. System.out.println("yes");
  32. }
  33. else
  34. {
  35. System.out.println("no ");
  36. }
  37.  
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement