Note 1 assume that program fragments embedded in whatever ad

Note 1: assume that program fragments embedded in whatever additional code is required to allow them to compile and run.
Note 2: \"Throw exception\" means that the program can be run but will throw an exception and fail to complete
D Question 3 What is the result of executing the following program fragment? into x new x 1); System out.print CxCij); Prints something other than 0or 1 Throws exception D Question 4 What is the result of executing the following program fragment? int x new int[1] System out.print Cx); Prints something other than 0 or 1 D Question 5 What is the result of executing the following program fragment? int y 3; int0 x new intCyli for (int i 1; i y; i++) xCij i; ,stem out print Prints something other than 0 or 1 WWu instructure.com Quiz: Chapter 71 2 pts 2 pts 2 pts

Solution

3.

int[] x = new x[1]; // Not a valid declaration

System.out.print(x[1]);

Therefore it throws an exception.

Option 4 is correct choice.

4.

int[] x = new int[1]; // Initialisation of array variable x
System.out.print(x);

Since array variable x is not initialised it prints something other than 0 or 1.

Option 3 is correct choice.

5.

int y=3; // Initially the y value is 3
int[] x = new int[y]; // Array declaration whose size is 3
for(int i=1;i<y;i++)

{
x[i]=i; // x[1] is assigned with 1
}
System.out.print(x[1]); // It prints 1 as output

Output :

1

Option 1 is correct choice.

Note 1: assume that program fragments embedded in whatever additional code is required to allow them to compile and run. Note 2: \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site