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);
7 Respostas
+ 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
+ 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
0
Thanks!
Why does it need to contain "String [] args"?
Also, does it execute the "i++" before it checks the "i < 5"?
0
the answer is 17
0
Answer is 17
0
Answer is 17
0
17