Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  Main3
Language: JAVA
Code:
import java.util.Scanner;

/**
 * Main3
 */
public class Main3 {

    public static void main(String[] args) {
        System.out.println("Input two int number:");
        int num1, num2;
        Scanner sc = new Scanner(System.in);
        num1 = sc.nextInt();
        num2 = sc.nextInt();
        int gcd = gcd(num1,num2);
        int lcm = (num1 * num2) / gcd;
        System.out.println("gcd:" + gcd);
        System.out.println("lcm:" + lcm);
    }

    public static int gcd(int val1,int val2){
       
        if(val1 < val2){
            int t;
            t = val1;
            val1 = val2;
            val2 = t;
        }

        while(true){
            int re = val1 % val2;
            if(re == 0){
                return val2;
            }
            val1 = val2;
            val2 = re;
        }

    }
}
Comments: