Advertisement
prem

Untitled

Oct 23rd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. public class InputLoop
  2. {
  3. public static void main(String[] args)
  4. {
  5. Scanner in = new Scanner(System.in);
  6. int number=0;
  7. System.out.print("Enter an integer or Q to quit: ");
  8. boolean two = false;
  9. boolean first = true;
  10. int max = 0;
  11. int secondmax = 0;
  12. int oddsum = 0;
  13. while (in.hasNextInt())
  14. {
  15. number = in.nextInt();
  16. if (!in.hasNextInt())
  17. {
  18. first = false;
  19. }
  20. System.out.print("Enter an integer or Q to quit: ");
  21. if (number > max)
  22. {
  23. secondmax = max;
  24. max = number;
  25. }
  26. if (number > secondmax)
  27. {
  28. secondmax = number;
  29. }
  30.  
  31. if (number == 2)
  32. {
  33. two = true;
  34. }
  35. if (number % 2 != 0)
  36. {
  37. oddsum = oddsum + number;
  38. }
  39. }
  40. if (!first)
  41. {
  42. System.out.println("no input");
  43. }
  44. else
  45. {
  46. System.out.println(secondmax);
  47. System.out.println(oddsum);
  48. if (two)
  49. {
  50. System.out.println("yes");
  51. }
  52. else
  53. {
  54. System.out.println("no ");
  55. }
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement