35, Predict the output:
class FindFac (
public static void main(String args[]) {
for(int i = 2; 1 <- 100; i++) {
System.out.print("Factors of" + i + ": ");
for(int j = 2; j <i; j++)
if((1K1) -- ) System.out.print(1 + " ");
System.out.println();
}
}
}
Answers
Answer:
here there is mistake in a statement please update that i.e.
change -100 in for loop to 100
if(i%j==0) you have to change that your program its is not if(1 k 1 --)
and please change
System.out.print(1 + " "); to System.out.print(j+ " ");
or else there is chance that you may get the error
Explanation:
coming to the output of the program
you will get the factors of all the numbers from 1 to 100
for example:
if i=6
then you will get the output as
"Factors of 6: 2
3"
similarly you will get this for all the numbers (1-100)
though 1 is a factor of every number here we are starting loop from 2 so, 1 is excluded and similarly we cannot get the number itself as the factor because we are ending the loop before that
please let me know if you need more clarification on this feel free to text me