
Write a JAVA program to read an initial two number x1 and x2, and determine if the two numbers are relatively prime. Two numbers are relatively prime. Two numbers are relatively prime if the only common factor between them is 1.

Hello Friend,
Try the following code:
import java.util.*;
class RelativelyPrime
{
public static int check(int a, int b) {
if (b == 0)
return a;
else
return check(b, a % b);
}
public static void main(String[] args)
{
RelativelyPrime rel=new RelativelyPrime();
Scanner input=new Scanner(System.in);
System.out.print("Enter first number: ");
int num1=input.nextInt();
System.out.print("Enter second number: ");
int num2=input.nextInt();
int res=rel.check(num1,num2);
if(res==1){
System.out.println("Numbers are relatively prime");
}
else{
System.out.println("Numbers are not relatively prime");
}
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.