import java.util.Scanner;
public class PrimeFactor{
public static void main(String [] args){
int number = 1, check = 0;
Scanner input = new Scanner(System.in);
while(check != 1){
System.out.println("Please enter an integer");
number = input.nextInt();
if(number == 0){
check = 1;
}
else if(number < 0){
System.out.print("-1 ");
number = number * -1;
while(number > 1){
int count = 2;
while(count <= number){
if(number% count == 0){
number = number / count;
System.out.print(" x " + count);
}else {
++count;
}
}
}
}
else if(number > 0){
int count = 2;
while(count <= number){
if(number% count == 0){
System.out.print(count);
number = number / count;
break;
}else{
++count;
}
}
while(count <= number){
if(number% count == 0){
number = number / count;
System.out.print(" X " +count);
}else{
++count;
}
}
}
System.out.println();
break;
}
}
}
No comments:
Post a Comment