×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Twin Prime calculate the power of the given number in Java
CO Prime - Java
16354    Arnab De    13/12/2018

Accept two no from the user and write a program in Java to check that those numbers are co- prime or not.

If any two given number has no common factor except 1 then that pair of the numbers known as co-prime. The co-prime numbers are may or may not be a prime number themself.

Let two numbers are 14 and 15.

The factors of 14 are 1, 2, 7, 14 and the factors of 15 are 1, 3, 5, 15 the common factor is 1. Therefore, 14 and 15 are the pair of co-prime. In others words, if the HCF of two numbers is 1 then, that pair of numbers are called co-prime. Co-prime numbers are also known as a relatively prime or mutually prime.

softetechnologies
import java.util.*;

public class CoPrime
{
    public static void main(String []args)
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the first no");
        int no1=sc.nextInt();
        System.out.println("Enter the second no");
        int no2=sc.nextInt();
        int temp;
        if(no2>no1)
        {
            temp=no2;
            no2=no1;
            no1=temp;
        }
        int r=-1;
        while(r!=0)
        {
            r=no1%no2;
            no1=no2;
            no2=r;
        }
        if(no1==1)
        {
            System.out.println("CO Prime Number");
        }
        else
        {
            System.out.println("Not a CO Prime Number");
        }
    }
}

softetechnologies
Twin Prime calculate the power of the given number in Java
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Rabindranath Tagore
Every child comes with the message that God is not yet discouraged of man.
Rabindranath Tagore
6173
84.64
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54733
25/06/2018     45842
01/01/2018     44059
28/06/2017     41606
02/08/2017     40703
01/08/2017     34696
06/07/2017     34477
15/05/2017     33693
11/09/2018     31240
14/07/2017     30554
softetechnologies