Home » JAVA Programming » Arrays » Question
  1. What is the output of this program?

    public class Result
    {
    public static void main(String args[])
    {
    int a[] = {5, 6, 7, 9, 11};
    for ( int k = 0; k < a.length - 1; ++k)
    System.out.print(a[k] + " ");
    }
    }
    1. 6 7 9 11
    2. 5 6 7 9
    3. 1 2 3 4
    4. 5 6 7 8
    5. None of these
Correct Option: B

a.length() is 5, so the loop is executed for 4 times.
output: 5 6 7 9



Your comments will be displayed only after manual approval.