Java Quiz based upon referencedesigner.com tutorial



Java Quiz # 1

The first Java Quiz covering Basics of Java.


Q1. What would be the value of x after the following statements were executed?

int x = 10;
switch (x)
{
case 10:
x += 15;
break;
case 12:
x -= 5;
break;
default:
x *= 3;
}


A . 5
B . 20
C . 25
D. 30

Q2. How many times will the following code print "Welcome to referencedesigner.com"?

int count = 0;
while (count++ <=3) {
System.out.println("Welcome to referencedesigner.com");
}


A . 1
B . 4
C . 3
D. 2

Q3. Which of the following is a correct for loop

A . for (i = 0; i <= 10; i++)
B . for (i <= 10; i++)
C . for i = 1 to 10
D. for (i = 0; i <= 10)

Q4. Which of the following is a correct java comment

A . //This is a java commment
B . <!--This is a java comment -->
C . /* This is java comment
D. 'This is a java comment

Q5. What would be the value of x after the following statements were executed?

int x = 15;
switch (x)
{
case 10:
x += 15; break;
case 12:
x -= 5; break;
default:
x *= 3;
}


A . 5
B . 20
C . 30
D. 45

Q6. How many lines are printed on the console when the following for loops are executed?

for (int i = 1; i < 5; i += 2) {
for (int j = 0; j < i; j++) {
System.out.println("learning java is fun at referencedesigenr.com");
}
}


A . 2
B . 4
C . 5
D. 20

Q7. Consider the following for loop

    int x = 4 ;
    for (i=0; i<=2; i++)
	{
	  x = x+3;
	}

What is the value of x at the end of for loop.


A . 5
B . 8
C . 13
D. 11

Q8. What is the value of destination after the following statement is executed ?

 
int zipcode = 02703;
int destination = 100; // default destination
switch (zipcode)
{
case 02703:
case 02035:
destination = 1;
break;
case 93710:
case 93720:
destination = 2;
break;
default:
destination = 0;
break;
}


A . 100
B . 0
C . 1
D. 2

Q9. What is the value of x after the following statements are executed?

int x = 5;
switch(x)
{
case 5:
x += 2;
case 6:
x++;
break;
default:
x *= 2;
break;
}


A . 6
B . 10
C . 7
D. 8

Q10. Consider the following while loop

    int i = 2 ;
    while (i<=10)
	{
	  i = i+3;
	}

What is the value of i at the end of while statement.


A . 5
B . 8
C . 13
D. 11


Try other quizzes

Quiz 1

Quiz 2

Quiz 3