-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx1.java
More file actions
49 lines (43 loc) · 1.09 KB
/
Ex1.java
File metadata and controls
49 lines (43 loc) · 1.09 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
49
package Ex1;
import java.util.Scanner;
public class Ex1 {
public static int gcd(int n1, int n2) {
if (n2 == 0)
return n1;
return gcd(n2, n1%n2);
}
public static int get_max_prime2(int max) {
for (int i = 2 ; i <= max; i++ ) {
if(max%i == 0 ) {
if(max/i > 1) {
return get_max_prime2(max/i);
}
else {
return i ;
}
}
}
return 1;
}
public static void main(String[] args) {
//Receiving 2 natural numbers by input or args
//printing the great common prime divider of these two numbers
//TODO Auto-generated method stub
Scanner inputy = new Scanner(System.in);
int a;
int b;
if (args.length > 0) {
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
}
else {
System.out.print("Enter the first number: ");
a = inputy.nextInt();
System.out.print("Enter the second number: ");
b = inputy.nextInt();
}
System.out.println("Max prime common divider: ");
System.out.println(get_max_prime2(gcd(a,b)));
inputy.close();
}
}