Hello, I'm working on a project that outputs the numbers 2 – 100.
Next to each number, it should list all the factors for that number.
If the number has no factors, it should print prime.
Ex.
2 prime
3 prime
4 2
5 prime
Having some difficulty so far. I'm aware I need to use loops, but I'm not sure what to %, and by what to determine if it's a factor.
This is my fail code so far: (I realize its horrible and is incomplete)
public class Prime { public static void main(String[] args) { findPrime(factors()); factors(); } public static void findPrime(int k) { int i = 2; int ans = i%k; while(i<=100) { System.out.println(ans); i++; } } public static int factors() { int k = 1; for(k = 1; k <=100; k++) { } return k; } }
Any help whatsoever is greatly appreciated. Thanks!