Sail E0 Webinar
Question


What is the output of this program?


class Output {
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < arr.length - 2; ++i)
System.out.println(arr[i] + " ");
}
}
Options:
A .  1 2
B .  1 2 3
C .  1 2 3 4
D .  1 2 3 4 5
Answer: Option B

arr.length() is 5, so the loop is executed for three times.
output:
$ javac Output.java
$ java Output
1 2 3


Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers