Examveda
Examveda

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);
        }
}

A. 10

B. 11

C. 9

D. 20

E. None of these

Answer: Option A

Solution(By Examveda Team)

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

This Question Belongs to Java Program >> Flow Control

Join The Discussion

Comments ( 3 )

  1. Sharvani Tirumalasetti
    Sharvani Tirumalasetti :
    11 months ago

    how

  2. Satyabrata Sahoo
    Satyabrata Sahoo :
    3 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

  3. Kamal Valecha
    Kamal Valecha :
    6 years ago

    plz explian

Related Questions on Flow Control