Answers for "java prime number factorisation"

5

prime factorization java

import java.util.Scanner;

public class PrimeFactors {
   public static void main(String args[]){
      int number;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter a number ::");
      number = sc.nextInt();
      
      for(int i = 2; i< number; i++) {
         while(number%i == 0) {
            System.out.println(i+" ");
            number = number/i;
         }
      }
      if(number >2) {
         System.out.println(number);
      }
   }
}
Posted by: Guest on June-06-2020

Code answers related to "java prime number factorisation"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language