0

Why doesn't it give me an output?

I copied a this from an example code, but I can't manage to get an output. The code: int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);

13th Nov 2016, 1:55 PM
Gabriel
7 odpowiedzi
+ 6
String[] args is used to pass parameters usually in linux systems to the main function and yes, i++ is executed before the check for i < 5, except for the first loop when it initialized and then checked
13th Nov 2016, 2:32 PM
Burey
Burey - avatar
+ 4
public class Program { public static void main(String[] args) { int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result); } } it needs to be defined inside a main function
13th Nov 2016, 2:11 PM
Burey
Burey - avatar
0
Thanks! Why does it need to contain "String [] args"? Also, does it execute the "i++" before it checks the "i < 5"?
13th Nov 2016, 2:29 PM
Gabriel
0
the answer is 17
5th Apr 2017, 7:40 AM
caroline kiuna
caroline kiuna - avatar
0
Answer is 17
23rd Mar 2018, 10:14 AM
Asiphe Gerald Nyamambi
Asiphe Gerald Nyamambi - avatar
0
Answer is 17
23rd Mar 2018, 10:22 AM
Asiphe Gerald Nyamambi
Asiphe Gerald Nyamambi - avatar
0
17
25th Jan 2019, 8:14 AM
Pooja Vatiya
Pooja Vatiya - avatar