Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class numbers {
- public static void main(String args[]) {
- System.out.println("Welcome to... ");
- Scanner sc = new Scanner(System.in);
- int a = sc.nextInt();
- int b = sc.nextInt();
- System.out.print(a + ", " + b + "\n");
- int c = gcd(a, b);
- System.out.println(c);
- System.out.println("First is: " + isprime(a) + "\n Second is: " + isprime(b));
- }
- public static int gcd(int n1, int n2) {
- int gcd;
- for (gcd = Math.abs(Math.min(n1, n2)); n1 % gcd != 0 || n2 % gcd != 0; gcd--)
- ;
- return gcd; // Return gcd
- }
- public static boolean isprime(int num) {
- int sqrt = (int) Math.sqrt(num);
- for (int base = 2; 2 <= sqrt; base++) {
- if (num % base == 0)
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement