Write a Java Programming:-
Input a number and print all the factors of the number.
please write the program not the output
Answers
Answered by
1
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);
}
}
}
Attachments:
Similar questions