Page 241 - CA_Blue( J )_Class9
P. 241
11 { c++; }
12 j++;
13 }
14 if(c==2)
15 System.out.println("Prime Number : " + i);
16 i++;
17 }
18 }
19 }
You will get the following output:
Dry Run of the above program:
i j if(i%j==0) c++ if(c==2) System.out.println(i)
3 1 3%1==0 c=1
2 3%2==0 c=1
3 3%3==0 c=2 true 3
4 1 4%1==0 c=1
2 4%2==0 c=2
3 4%3==0 c=2
4 4%4==0 c=3 false
5 1 5%1==0 c=1
2 5%2==0 c=1
3 5%3==0 c=1
4 5%4==0 c=1
5 5%5==0 c=2 true 5
6 1 6%1==0 c=1
2 6%2==0 c=2
3 6%3==0 c=3
Nested Loop 239

