Computer Science, asked by BrainlyProgrammer, 9 hours ago

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 anindyaadhikari13
8

\texttt{\textsf{\large{\underline{Solution}:}}}

Given co‎de -

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 co‎de -

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") ;

}

\texttt{\textsf{\large{\underline{Errors}:}}}

  • Semi-colon missing on line 2.
  • I%2 returns integer value and not boolean. Replaced I%2 with I%2==0.

\texttt{\textsf{\large{\underline{Outpu{t}}:}}}

0

4

8

12

16

20

24

28

32

36

40

44

48

Similar questions