Computer Science, asked by krrishsingh0082, 2 months ago

Write a program in Java to accept a number from user, calculate and display all the prime

factors of the number.​

Answers

Answered by Saarthak15Sharma
4

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);

     }

  }

}

pls mark it as brainliest

Similar questions