Here is what I am looking to do. I have listed my code below for your reference. Thank you in advance for any help you can provide.
Goal: Find Prime Factorizations of a number n. Then concatenate the prime factors into one number, x. Then Take that number, x, and divide by n. If x%n = 0, print True. If x%n != 0, print false. (i.e. if n = 100, Prime Factors are 2,2,5,5. Turn into 2255, then take 2255/100. 2255%100 != 0, Print False. )
What I have now prints out the prime factors correctly for some numbers, but when I try to use another prime number, the program will quit. Also, If I use a number like 123, it will only print out 3, not 3 and 41. Do you have any suggestions?
If possible, ideally I would like to run this for numbers j= 2 through any upper bound I set, call the upper bound U, and if any value for j = 2 through U yields a result that is true (from above) Then I would like to print that j value.
import acm.program.*;
import acm.util.*;
import java.util.Scanner;
import java.util.Arrays.*;
// -------------------------------------------------------------------------
public class FactorsLoop extends ConsoleProgram
{
//~ Instance/static variables .............................................
private RandomGenerator rgen = RandomGenerator.getInstance();
//~ Constructor ...........................................................
// ----------------------------------------------------------
/**
* Creates a new ForLoops object.
*/
public void run()
{
//
int n1 = 10000;
int n2 =(n1);
double U = 10000;
StringBuilder factors = new StringBuilder();
for (int j = 2; j < U; j++) {
for (int i = 2; i*i <= n1; i++) {
// if i is a factor of N, repeatedly divide it out
while (n1% i == 0) {
n1 = n1 / i;
factors.append(Integer.toString(i));
}
}
}
double newNumber = Integer.parseInt(factors.toString());
double x = (newNumber / n2);
print(x);
if ( newNumber % n2 == 0 ){
println(n2);
}
}
}