I am a beginner and let's just cut to the chase.
Here is the code I've written.
Quote:
import java.io.*;
import java.util.Scanner;
public class primes {
public static void main(String[] args) {
double x=2d, y=0d, z=0d, count=0; //z=13699293826d
Scanner sc = new Scanner(System.in);
System.out.print ("Enter a number: ");
z=sc.nextFloat();
while(x<z)
{
y=z%x;
if(y==0)
{
System.out.println(x);
x=1;
z=z/x;
}
x++;
}
System.out.println (z);
}
}
|
Here is the problem:
1. Sometimes, a number has so many powers of 2 that the output window is filled with 2's. Is there any way to output one "2" and then the number of times it appears?
2. Is there any better way to write a program that completes this objective? I don't mind starting from scratch.
Thanks!