Correct Answer : Get Lastest Questions and Answer : Explanation: The first println prints variable a with value 1 and then increases the variable to 2.
Question : You have been given following code
public class Test { public static void main(String[] args) { int arr[] = new int[4]; arr[0] = 1; arr[1] = 2; arr[2] = 4; arr[3] = 5; int sum = 0; try { for (int pos = 0; pos <= 4; pos++) { sum = sum + arr[pos]; } } catch (Exception e) { System.out.println("Invalid index"); } System.out.println(sum); } }
Correct Answer : Get Lastest Questions and Answer : Explanation: The loop for (int pos = 0; pos <= 4; pos++) { it should be pos <= 3, causes an exception, which is caught. Then the correct sum is printed.
Question : : int [] array = {1,2,3,4,5}; for (int i: array) { if ( i < 2) { keyword1 ; } System.out.println(i); if ( i == 3) { keyword2 ; }}
1. int sum(int first, int second) { first + second; } 2. int sum(int first, second) { return first + second; } 3. Access Mostly Uused Products by 50000+ Subscribers 4. int sum(int first, int second) { return first + second; }
5. void sum (int first, int second) { return first + second; }
1. sc: class Object asc: class AnotherSampleClass 2. sc: class SampleClass asc: class AnotherSampleClass 3. Access Mostly Uused Products by 50000+ Subscribers 4. sc: class AnotherSampleClass asc: class AnotherSampleClass