In: Computer Science
Write a program factor that prints the prime factors of a specified non-negative integer. The integer will be provided as a command-line argument.
You may assume that the integer will be greater than 1 and less than or equal to the largest signed integer on your platform (that is, you may use an int).
class PrimeFactors {
public static void main(String args[]) {
int number =
Integer.parseInt(args[0]);
System.out.println("Given Number is
: " + number);
System.out.print("Prime Factors are
: ");
//iterating till the given
number
for (int i = 2; i <= number;
i++) {
while (number %
i == 0) {
System.out.print(i + " ");
number = number / i;
}
}
if (number < 1)
System.out.println(number);
}
}