forked from sujana-kamasany/javacodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuzzNumber.java
37 lines (33 loc) · 1.34 KB
/
BuzzNumber.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.company;
import java.util.Scanner;
public class BuzzNumber {
public static void main(String[] args) {
boolean isPositive = false;
// while loop and isPositive flag will assure integer entered is positive
while (isPositive == false) {
int checkBuzz = -1;
System.out.println("Input an integer: ");
boolean validEntry = false;
// while loop with try catch to make sure input is valid integer
while (validEntry == false) {
try {
Scanner in = new Scanner(System.in);
checkBuzz = in.nextInt();
validEntry = true;
} catch (Exception e) {
System.out.println("You didn't enter an integer. Re-enter...");
}
}
// if statement to continue loop if input was a negative number.
if (checkBuzz < 0) {
continue;
}
boolean isBuzzNumber = false;
if (checkBuzz % 7 == 0 || checkBuzz % 10 == 7){ // Checks if input can be divisible by 7 or ends with 7
isBuzzNumber = true;
}
isPositive = true;
System.out.println("isBuzzNumber: " + isBuzzNumber);
}
}
}