Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class InputLoop
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- int number=0;
- System.out.print("Enter an integer or Q to quit: ");
- boolean two = false;
- boolean first = true;
- int max = 0;
- int secondmax = 0;
- int oddsum = 0;
- while (in.hasNextInt())
- {
- number = in.nextInt();
- if (!in.hasNextInt())
- {
- first = false;
- }
- System.out.print("Enter an integer or Q to quit: ");
- if (number > max)
- {
- secondmax = max;
- max = number;
- }
- if (number > secondmax)
- {
- secondmax = number;
- }
- if (number == 2)
- {
- two = true;
- }
- if (number % 2 != 0)
- {
- oddsum = oddsum + number;
- }
- }
- if (!first)
- {
- System.out.println("no input");
- }
- else
- {
- System.out.println(secondmax);
- System.out.println(oddsum);
- if (two)
- {
- System.out.println("yes");
- }
- else
- {
- System.out.println("no ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement