-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsFactor.java
More file actions
39 lines (29 loc) · 856 Bytes
/
Copy pathIsFactor.java
File metadata and controls
39 lines (29 loc) · 856 Bytes
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
import java.util.Scanner;
public class IsFactor {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
//isFactor
System.out.println("Welcome!\nPlease enter your first number (divisor): ");
int k = sc.nextInt();
System.out.println("Please enter your second number (dividend): ");
int n = sc.nextInt();
boolean factor = isFactor(k, n);
if (factor == true) {
System.out.println("These numbers are divisible! " + n + " is divisible by " + k + "!");
}else {
System.out.println("These numbers are not divisible. " + n + " is not divisible by " + k + ".");
}
sc.close();
}
public static boolean isFactor(int k, int n) {
boolean result = true;
if (n % k == 0) {
result = true;
}
else {
result = false;
}
return result;
}
}