Prime factors of a number in java

Java code to get the prime factors of give number




import java.io.*;

class Test {
     public static void main(String[] args) throws IOException {
          int num,i=1,j,k;
          System.out.println("Enter the range:");
          BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
          num=Integer.parseInt(br.readLine());

          while(i<=num){
              k=0;

              if(num%i==0){
                   j=1;

                   while(j<=i){
                        if(i%j==0)
                             k++;
                        j++;
                   }

                   if(k==2)
                        System.out.println(i+" is a prime factor");
              }
              i++;
          }
     }
}


Conversion of binary number to decimal number using java programming language


Post a Comment