Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Divisibility.java #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Divisibility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
}