I am making a function that can turn a number into a simplified radical square root. I have so far made a function that can return the factors of a number. I want to turn the string into an array so I can index through the numbers in a for loop and test if they have a perfect square root. How can I do this?
This is what I have so far:
public static void factor(int num) { for (int i = 1; i <= num; ++i) { if (num % i == 0) { System.out.println(i); } } }
inputing the number 20 outputs
1 2 4 5 10 20
I want to turn this into {1, 2, 4, 5, 10, 20}
https://stackoverflow.com/questions/66502252/turning-multi-line-string-into-array-in-java March 06, 2021 at 12:06PM
没有评论:
发表评论