Heyo Java begginers!!
[Challenge]
Find out the mistake in the snippet below:-
for(int I=0,j=I+2;I<25;I+=2) {
boolean k=I%2
if(k)
System.out.println(j*I) ;
else
System.out.print("\t") ;
}
Answers
Answered by
8
Given code -
for(int I=0,j=I+2;I<25;I+=2) {
boolean k=I%2
if(k)
System.out.println(j*I) ;
else
System.out.print("\t") ;
}
Corrected code -
for(int I=0,j=I+2;I<25;I+=2) {
boolean k=I%2==0;
if(k)
System.out.println(j*I) ;
else
System.out.print("\t") ;
}
- Semi-colon missing on line 2.
- I%2 returns integer value and not boolean. Replaced I%2 with I%2==0.
0
4
8
12
16
20
24
28
32
36
40
44
48
Similar questions