I need a JAVA code for the below assignment
1) Write a program that takes a whole number input from a user and determines whether it’s prime. If the number is not prime, display its unique prime factors. Remember that a prime number’s factors are only 1 and the prime number itself. Every number that’s not prime has a unique prime factorization For example, consider the number 54. The prime factors of 54 are 2,3,3 and 3. When the values are multiplied together, the result is 54. For the number 54, the prime factors output should be 2 and 3. Use Sets as part of your solution.
//PrimeFactors.java
import java.util.*;
public class PrimeFactors{
private static boolean isPrime(int n){
for(int i = 2;i<n;i++){
if(n%i == 0) {
return false;
}
}
return true;
}
public static void main(String args[]){
int n,i = 2,input;
ArrayList<Integer> queue = new ArrayList<Integer>();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter n: ");
n = scanner.nextInt();
input = n;
if(isPrime(input)){
System.out.println(input+" is prime number");
}
else {
while (n > 1) {
if (isPrime(i)) {
while (n % i == 0) {
queue.add(i);
n = n / i;
}
}
i++;
}
System.out.print("Prime factors for " + input + ": ");
for(i = 0;i<queue.size();i++){
System.out.print(queue.get(i)+ " ");
}
}
}
}
I need a JAVA code for the below assignment 1) Write a program that takes a...