calculate prime factors of a number java
public static void main(String[] args) {
int n=12;
for(int i=2; i<=n; i++){
while(n%i==0){
n=n/i;
System.out.println(i); //prints 2 2 3
}
}
}
calculate prime factors of a number java
public static void main(String[] args) {
int n=12;
for(int i=2; i<=n; i++){
while(n%i==0){
n=n/i;
System.out.println(i); //prints 2 2 3
}
}
}
program to find prime factors of a number in 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);
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us