Advertisement
nate23nate23

note 9.12

Sep 12th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class numbers {
  4.     public static void main(String args[]) {
  5.         System.out.println("Welcome to... ");
  6.         Scanner sc = new Scanner(System.in);
  7.         int a = sc.nextInt();
  8.         int b = sc.nextInt();
  9.         System.out.print(a + ", " + b + "\n");
  10.         int c = gcd(a, b);
  11.         System.out.println(c);
  12.         System.out.println("First is: " + isprime(a) + "\n Second is: " + isprime(b));
  13.  
  14.     }
  15.  
  16.     public static int gcd(int n1, int n2) {
  17.         int gcd;
  18.         for (gcd = Math.abs(Math.min(n1, n2)); n1 % gcd != 0 || n2 % gcd != 0; gcd--)
  19.             ;
  20.         return gcd; // Return gcd
  21.     }
  22.  
  23.     public static boolean isprime(int num) {
  24.         int sqrt = (int) Math.sqrt(num);
  25.         for (int base = 2; 2 <= sqrt; base++) {
  26.             if (num % base == 0)
  27.                 return false;
  28.         }
  29.         return true;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement