×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Twin Prime calculate the power of the given number in Java
CO Prime - Java
15128    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.
Sri Sri Ramakrishna Paramahamsa
Have love for everyone, no one is other than you.
Sri Sri Ramakrishna Paramahamsa
1988
55.57
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     42977
01/01/2018     36288
25/06/2018     34740
28/06/2017     34401
02/08/2017     32736
01/08/2017     27246
06/07/2017     27062
15/05/2017     26664
14/07/2017     22275
21/04/2018     20918
softetechnologies