Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- 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 max = false;
- boolean secondmax=false;
- int oddsum = 0;
- while (in.hasNextInt())
- {
- number = in.nextInt();
- if (number == 2)
- {
- two = true;
- }
- if (number % 2 != 0)
- {
- oddsum = oddsum + number;
- }
- System.out.print("Enter an integer or Q to quit: ");
- }
- 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