ExamVeda
Login
Home
This question belongs to Java Program Flow Control
Flow Control
?

Determine output:
public class Test{
        public static void main(String args[]){
                int i, j;
                for(i=1, j=0;i<10;i++) j += i;
                System.out.println(i);
        }
}

Answer & Solution
Correct Answer: Option A
In giving a program for loop will be break when i=10. Since after for only one statement execute ( j += i;) because brace is not mentioned and after that print statement will execute and print i=10
Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Sharvani Tirumalasetti
Sharvani Tirumalasetti 3 years ago
how
Satyabrata Sahoo
Satyabrata Sahoo 5 years ago
answer will be 45 since only one statement is there below for loop, so no braces required. hence it will execute j+=i inside for loop i.e 9 times
Kamal Valecha
Kamal Valecha 8 years ago
plz explian