CHECK PRIME AND PRINT SUM OF THEIR FACTORS

WAP to check if a number is prime or not.

import java.util.*;

class E7PrimeNumbers

{

    public static void main()

    {

        int x,i=1,sum=0;

        System.out.println("Enter an integer to print sum of their factors \n\n");

        Scanner in=new Scanner(System.in);

        x=in.nextInt();



        while((x+1)>i)

        {

            if(x%i==0)

                sum= sum +i;

            i++;

        }

        if(sum==x+1)

            System.out.println(" It is prime ");

        else 

            System.out.println(" It is not prime  ");

        System.out.println(" Sum of factors is   "+ sum);

    }

}


For Any Desired Program comment below. WE WILL TRY OUR BEST TO MAKE THAT PROGRAM AVAILABLE.

Comments

Post a Comment

Popular Posts