Predict the output of the following code.

public class Main
{
  public static void main(String[] args)
  {
  int[] arr1={5,6,3,1,2};
  int n=arr1.length+1;
        int s=n*(n+1)/2;
        int r=0;
        for (int i = 0; i < arr1.length; i++) {
            r+=arr1[i];
        }
        int f=s-r;
        System.out.println(f);
    }
} 

4

3

7

5

Verified Answer
Correct Option - a

To get all Infosys Certified Java SE11 Developer Exam questions Join Group https://bit.ly/infy_premium_group

We're passionate about offering best placement materials and courses!! A one stop place for Placement Materials. We daily post Offcampus updates and Placement Materials.

Qtr No. 213, New Town Yehlanka Indore 454775

admin@prepflix.in