-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathDivisibility.java
More file actions
48 lines (40 loc) · 1.42 KB
/
Divisibility.java
File metadata and controls
48 lines (40 loc) · 1.42 KB
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
38
39
40
41
42
43
44
45
46
47
48
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* This program will check if an Input number is divisible by 7 or any other input number.
*
*/
public class Divisibility {
public static void main(String[] args) throws IOException {
readAndPrint();
}
private static void readAndPrint() throws IOException {
int divideBy = 7;
int number = readNumber("Enter any number between 1-100 in Console:");
checkDivisibility(number, divideBy);
String decision = readValue("If you would you like to check divisibility of " + number
+ "against a different number, enter \"Y\" ?");
if ("Y".equalsIgnoreCase(decision)) {
divideBy = readNumber("Enter any number between 1-100 to in Console:");
checkDivisibility(number, divideBy);
}
}
private static int readNumber(String message) throws IOException {
return Integer.parseInt(readValue(message));
}
private static String readValue(String message) throws IOException {
System.out.println(message);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
System.out.println("Input: " + input);
return input;
}
private static void checkDivisibility(int number, int divideBy) {
if (number % divideBy == 0) {
System.out.println(number + " is divisible by " + divideBy);
} else {
System.out.println(number + " is not divisible by " + divideBy);
}
}
}