Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GCD_LCM{
- public static void main(String[] args){
- java.util.Scanner sc=new java.util.Scanner(System.in);
- System.out.print("Enter a : ");
- int a=sc.nextInt(),aI=a;
- System.out.print("Enter b : ");
- int b=sc.nextInt(),bI=b;
- while(b!=0){
- int r=a%b;
- a=b;
- b=r;
- }
- System.out.println("The GCD of a and b is "+a);
- System.out.println("The LCM of a and b is "+((aI*bI)/a));
- }
- }
Add Comment
Please, Sign In to add comment