public static int count int a new int5 a0 0 a1 1 for int

public static int count() {int[] a = new int[5]; a[0] = 0; a[1] = 1; for (int i=2; i

Solution

Ans)Here the function returns 14.

Explanation in comments:

   private static int count() {

//Creating an Integer array which is of size 5

int a[] = new int[5];

//Assigning Zero(0) to the first element of the array

       a[0] = 0;

//Assigning one(1) to the second element of the array
       a[1] = 1;

/*This Loop iterates for 3 times

*This loop populates the value to thirst,fourth,fifth elements of the array.

*/

       for (int i = 2; i < a.length; i++) {

//In the First Iteration, a[2]=2+1+0 =3 ( since i=2 , a[1]=1 , a[0]=0 )

//In the Second Iteration a[3]=3+3+1=7 ( since i=3 , a[2]=3 , a[1]=1 )

//In the Third Iteration a[4]=4+7+3=14 ( since i=4 , a[3]=7 , a[2]=3 )
           a[i] = i + a[i - 1] + a[i - 2];
       }
       return a[4] ; //So this will return 14

   }

____________________________Thank You

 public static int count() {int[] a = new int[5]; a[0] = 0; a[1] = 1; for (int i=2; i SolutionAns)Here the function returns 14. Explanation in comments: private

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site