0
Write a program in Java to print prime factors of a number entered as per user's choice.
4 odpowiedzi
+ 8
Here is one solution in C++ language, you try to customize it for yourself.😉
• https://code.sololearn.com/cPj45ZyHsmz8/?ref=app
+ 8
Vatsal Agarwal sorry,
You want to find the prime factors of a given number.
Here is one way to do it but first make a correction, pay attention how you write the main() method!
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
// Enter a number:
int n = in.nextInt();
for (int i = 2; i*i <= n; i++) {
while (n % i == 0) {
System.out.printf("%d ", i);
n /= i;
}
}
if (n > 1) {
System.out.printf("%d", n);
}
}
Also, check this out:
• https://www.sololearn.com/learn/4714/?ref=app
+ 7
You should accompany your question with an attempt.
This Q&A forum is for specific programming questions.
https://www.sololearn.com/Discuss/1316935/?ref=app
Please show your code here so that we can help you
https://www.sololearn.com/post/75089/?ref=app
+ 5
There are plenty of bugs.
First of all: Correct the indentations. That will make it easier for you to find out that you closed a curly bracket at the wrong line....
Also:
Line 7 println (typo)
Line 8 nextInt() it's a method
Line 10 int j isn't initialized