0
Massive
what values will the algorithm give and say why? int result = 0; for(int i = 0; i < 5; i++); if(i == 3); result += 10; else result +=i; System.out.println(result)
5 ответов
+ 10
Code will give error
first of all, since the for loop has more than one statement it should have curly braces enclosing all its statements
secondly the if statement will give an error because "i" exists only in the for loop
thirdly placing a semicolon after the if statement terminates it so "result += 10" executes irrespective of whether the if condition is true or false
+ 6
int result = 0;//assigned 0 to result
for(int i = 0; i < 5; i++);
if(i == 3)
result += 10;
else
result +=i;
System.out.println(result)
for i=0 else part evaluate and result+=0=0
for i=1 else part evaluated and result+=1=1
for i=2 else part evaluate and result+=2=3
for i=3 if part evaluate and result+=10=13
for i=4 else part evaluate and result+=4=17
so output become 17 but it is only when the semicolon is not present after if statement
0
yes, its lessons Java, and answer this it algorithm 17, Whyyyy?
0
thanx
0
thx