0% found this document useful (0 votes)
170 views1 page

Test Your Understanding - Introduction To Java - Attempt Review

Uploaded by

Sujai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
170 views1 page

Test Your Understanding - Introduction To Java - Attempt Review

Uploaded by

Sujai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

Started on Sunday, 27 October 2024, 4:00 PM

 State Finished
Completed on Sunday, 27 October 2024, 4:07 PM
 Quiz
Time taken 6 mins 58 secs
navigation
Marks 7.00/11.00

Grade 63.64 out of 100.00 1 2 3 4
Oops!!! You have scored below 80% ..So Kindly make

Feedback necessary preparations and reattempt.. 5 6 7 8

9 10 11
Question
1.00/1.00
1 Show one page at

a time
What will be the output of the program? Finish review
Given:
10. int x = 0;

11. int y = 10;

12. do {

13. y--;
14. ++x;

15. } while (x < 5);


16. System.out.print(x + "," + y);

What is the result?

Select one:
a. 6,5

b. 5,5

c. 6,6

d. 5,6 

x is assigned 0 and y, 10 initially. During each iteration x is


incremented by 1 and y is decremented by 1.

The iteration stops when x equals 5. At this stage y also would


have reached the value 5. Hence the output 5 5.
The correct answer is: 5,5

Question
0.00/1.00
2

Fill in with appropriate datatype.

switch(

long

 )

case value1 : ..........................

case value2 : ..........................

.......................................

default:

System.out.println("Hello");

Switch in java works with primitive data types byte, short, char
and int;
wrapper classes like Character, Byte, Short and Integer;
enumerated types (added in java 5) and String class (added in
java 7)

The correct answer is:


Fill in with appropriate datatype.

switch([byte])
{

case value1 : ..........................


case value2 : ..........................

.......................................

default:
System.out.println("Hello");
}

Question
1.00/1.00
3

What value is stored in i at the end of this loop?


for(int i =1;i<=10;i++)

Select one:
a. 10

b. 9

c. 11

d. 1

The program control will exit the for loop only when the condition
specified in the for loop has failed. Hence, the value of i will be 11.
The correct answer is: 11

Question
1.00/1.00
4

What will happen when the following code is compiled and run in
Java 1.8?
int i = 1, j = -1;
switch (i)
{
case 0, 1: j = 1; /* Line 4 */
case 2: j = 2;
default: j = 0;
}
System.out.println("j = " + j);

Select one:
a. j = 0

b. j = 1

c. j = -1

d. Compilation fails.

One can not specify multiple case labels with commas, as in line
4. Hence compilation error.
The correct answer is: Compilation fails.

Question
0.00/1.00
5

What will be the output of the program?


for(int i = 0; i < 3; i++)
{
switch(i)
{
case 0: break;
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
System.out.println("done");

Select one:
a. one two doneone two done

b. one two three done

c. done 

d. one two three two three done

Switch takes the values 0, 1 and 2.

Case 0 has nothing to execute.

Execution of Case 1 is followed by 2 and 3 since there's no break


statement encountered. So, one two three.

Execution of Case 2 is followed 3 since there's no break statement


encountered like before. So, two three.

This is followed by "done".

The correct answer is: one two three two three done

Question
1.00/1.00
6

Which of the following loops will execute the body of loop even
when condition controlling the loop is initially false?

Select one:
a. for

b. do-while

c. while

Your answer is correct.

The correct answer is:


do-while

Question
0.00/1.00
7

What is the output of this program?

class selection_statements {
public static void main(String args[])

int var1 = 5;
int var2 = 6;

if ((var2 = 1) == var1)

System.out.print(var2);
else

System.out.print(++var2);

}
}

Select one:
a. 3

b. 1 

c. 2

d. 4

Observe the if construct. var 2 is assigned 1. 1 does not equal 5,


hence else block will get executed. Pre increment to var2 results in
2 (var2 variable now has the value 1, not 6). Hence 2 gets printed.

The correct answer is: 2

Question
1.00/1.00
8

for

 looping structure should be used when the iterations are

known.

Your answer is correct.


The correct answer is:

[for] looping structure should be used when the iterations are


known.

Question
1.00/1.00
9

French curly braces { } is a must if the for loop executes more


than one statement. State true or false.

Select one:
True 

False

The correct answer is 'True'.

Question
1.00/1.00
10

The break statement causes an exit ___________

Select one or more:


a. from the innermost loop

b. none of the options

c. from the innermost switch. 

d. from the program.

Your answer is correct.

The correct answers are: from the innermost switch. , from the
innermost loop

Question
0.00/1.00
11

What is the output of this program?


1. class Crivitch {
2. public static void main(String [] args) {
3. int x = 10;
4.
5. do { } while (x++ < y);
6. System.out.println(x);
7. }
8. }

Which statement, inserted at line 4, produces the output 12?

Select one:
a. int y=11;

b. int y=13;

c. int y=12; 

d. int y=10;

Your answer is incorrect.

The correct answer is:


int y=11;

Finish review

You might also like