Write a Java Programming:-
Input a number and print all the factors of the number.
please write the program not the output
Share
Write a Java Programming:-
Input a number and print all the factors of the number.
please write the program not the output
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
public class Test {
public static void main(String args[]) {
System.out.print("Enter a number: ");
int n = (new java.util.Scanner(System.in)).nextInt();
System.out.println("Prime Factor of number " + n + " is: ");
while (n % 2 == 0) {
System.out.println(2);
n /= 2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
System.out.println(n);
n /= i;
}
}
if (n > 2) {
System.out.println(n);
}
}
}