0
Someone please explain me this code
public class Program { public static void main(String[] args) { int result = 0; for (int x=0; x<5; x++){ if (x==3){ result += 10; } else { result +=x; } } System.out.println(result); } }
2 odpowiedzi
+ 2
This program will use result as storage variable to store x value in a for loop iteration for five time started from zero but checking first the value of x if equal to three if x equal three increment by 10 else by 1 so 0+1+2+10 +4 is the final value stored in result.
+ 1
if x is equal to 3 program adds 10 to result otherwise it adds number 0,1,2,4 so the answer will be 17