Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following Java 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] + ” “);
}
}

What will be the output of the following Java 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] + ” “);
}
}
a) 1 2
b) 1 2 3
c) 1 2 3 4
d) 1 2 3 4 5

Answer: b
Explanation: arr.length() is 5, so the loop is executed for three times

Join The Discussion