Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code segment in Listing 1. when completed, creates numbs an array of integer

ID: 3829115 • Letter: T

Question

The code segment in Listing 1. when completed, creates numbs an array of integers, of size 2 that stores 13 and 7 as its first and respectively, and then prints their sum. Complete the code segment by providing the missing code. Using the line numbers, give a valid alternate execution sequence that gives the same output. Give another valid alternate execution sequence, if one exists, that gives the same output or indicate that no other such sequence exists. What would the code segment in Listing 2 output?

Explanation / Answer

A)

1) int[] nums;

2) nums=new int[2];

3) nums[0]=13;

4) nums[1]=7;

5) System.out.printf(“sum: %d ”,nums[0]+nums[1]);

___________________

Another sequence of line which gives the same output

1) int[] nums;

2) nums=new int[2];

3) nums[1]=7;

4) nums[0]=13;

5) System.out.printf(“sum: %d ”,nums[0]+nums[1]);

___________________

B)

Output:

-*-*-
-*-*-
-*-*-

Explanation:

int i=1,j;
       while(i<=3) //The outer loop execute for three times
       {
           for(j=1;j<=5;j++) //the inner loop execute for 5 times where j values randing from 1 to 5
           {
               if(j%2==0) //checking whether the j is even or odd
               {
                   System.out.print("*"); //for every even value of j,this prints *
               }
               else
               {
                   System.out.print("-"); //For every odd values of j,this will prints -
               }
              
           }
           System.out.println();   
           i++;
       }

______________