I'm new to coding and I'm required to have a return statement but I'm struggling on how to return the values of count from my while loop. I put a link of picture of what I'm getting plus my code is below.
Also I added a printout of "is factor of number " + count just so I can see what count is doing during the while loop. What I really want to do is return these values so when I hit run these values and only these values appear.
Here is my code:
package allFactors;
public class AllFactors {
public static void main(String[] args) {
System.out.println(printFactors(25));
}
public static int printFactors(int number) {
if (number < 1) {
System.out.println("Invalid Value ");
}
int count = 0;
while (count <= number) {
count++;
if (number % count == 0) {
System.out.println(count + " is factor of number ");
continue;
}
}
return count;
}
}
my CURRENT output is as follows:
1 is factor of number
5 is factor of number
25 is factor of number
26
- i only put system.out.println(count + " is factor of number "); BECAUSE i want to see what my count value is, NOW i dont want to return count; because that just gives me 26, i want to JUST return 1, 5 and 25. Because these numbers are all factors of 25; once i can do this i will delete my system.out.println(count + " is factor of number "); line of code because it is not necessary. I hope this question make sense
DESIRED OUTPUT
1
5
25