Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package triange;
- import java.util.Scanner;
- public class Gcd {
- public static int gcd(int f,int g) {
- int c=0;
- for (double i = 1; i <= f; i+=1){
- if(Math.round(f/i)==(f/i)) {
- for (double j = 1; j <= g; j+=1){
- if( Math.round(g/j)==g/j && j==i) {
- c =(int)Math.round(i);
- }
- }
- }
- }
- return c;
- }
- public static void main(String[] args) {
- Scanner line = new Scanner(System.in);
- System.out.println("num1?");
- int num = line.nextInt();
- System.out.println("num2?");
- int num2 = line.nextInt();
- System.out.println(gcd(num,num2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement