Create Software Components 

Using Java Level 2

 

 

Course Info

Scheme

Resources

Tutorials

Java Demos

Utilities

Links


 

    Quiz 6

Program Flow Control

There are 15 questions

Question 1.         

What is the result of the following Boolean expression?

 

int no1 = 6, no2 = -2;

(no1 == 6) && (no2 > 2)

 

(a)   true

(b)   false

Question 2.         

What is the result of the following Boolean expression?

 

int no1 = 6, no2 = -2;

(no1 == 6) || (no2 > 2)

(a)   true

(b)   false

Question 3.         

What is the result of the following Boolean expression?

 

int no1 = 6, no2 = -2;

(no1 == 6) && !(no2 > 2)

(a)   true

(b)   false

Question 4.         

What is the result of the following Boolean expression?

 

int no1 = 6, no2 = -2;

(no1 == 6) && ((no2 != 3) || (no2 > 2))

(a)   true

(b)   false

Question 5.     

 If a = 2 and b = 3 what is the result of evaluating this expression:

 
      ! ((a  !=  0) || (b  < =  5))

(a)   false

(b)   true

Question 6.         

Which one of the following is not an example of a Boolean expression?

 

(a)   x = 6

(b)   str.equals("fool")

(c)   cause == effect

(d)   result = b < c  

Question 7.         

Which one of the following is an invalid Boolean expression?

 

int k = 0, j = 2;  

boolean b1 = true, b2 = false;

String str = "hi";

char ch = 'a';

 

  1. j <= k

  2. b1 == !b2

  3. str == ch

  4. ch != 'A'

 

(a)   expressions 1

(b)   expressions 2

(c)   expressions 3

(d)   expressions 4 

Question 8.         

What is the output produced by the following code fragment?

 

int num = 0;

num++;

if (num > 0) 

  System.out.print("Hello ");

else

  System.out.print("Goodbye ");

(a)   Hello

(b)   Goodbye

(c)   Hello Goodbye

(d)   This code won't compile so no output is produced

Question 9.         

What will the following statement sequence output?

 

int a = 6;

int b = 6;

if (a==b)

System.out.println("Equal");

else

System.out.println("Definitely Not Equal");  

 

(a)  Definitely Not Equal

(b)   Equal

(c)  The program doesn't compile because = = cant be used here

(d)   Equal Not equal

Question 10.         

What is the final output after executing the class MyClass below?

 

class MyClass {

public static void main( String args[] ){

int my_number = 3;

int your_number;

while ( my_number < 10 ){

your_number = my_number;

my_number += your _number * 2;

}

System.out.println( "Answer is " + my_number );

}

}  

 

(a)    Answer is 15

(b)    Answer is 13

(c)    Answer is 27

(d)    Answer is 15

Question 11.         

What is the value of i after the following code fragment has finished executing?

 

int i = 0;

int j = 11

while (i < j){

i++;

}

 

(a)   12

(b)   11

(c)   10

(d)   Null

Question 12.         

 What does the last statement finally print?

int k = 0;

for(int i=1; i<5; i++){

 k++;

}

System.out.println("i + k = " + (i + k) );

 

(a)   i + k = 4

(b)   i + k = 5

(c)   i + k = 8

(d)   The code doesn't compile since the scope of i is limited to the         for loop.

Question 13.         

Which of the following loops will not be entered?

 

(a)   while (true){do something...}

(b)   while (!false){do something...}

(c)   for(int i=2; i==1; i++){do something...}

(d)   for(int i=0; i!=1; i++){do something...}

Question 14.         

 Which of the following loops will repeat indefinitely?

 

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

(b)   for(int i=2; i<=10; i++){

(c)   for(int i=2; i==1; i++){

(d)   for(int i=2; i!=1; i++){

Question 15.         

I wish for a loop to repeat 10 times.  Which of the following does this?

 

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

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

(c)   for(int i=1; i==10; i++){

(d)   for(int i=1; i!=10; i++){

 

        

 

  Site Home 

Java Home   

  Forum  

Course Info

Welcome

Overview

Assessment

Qualification

Scheme of Work

Assignments

Resources

Information

Blackboard

Learning Center

Web Materials

Reading

Java Demos

Utilities

Links

Lecture Materials

Tutorials & Notes

Exercises

Activities

Quizzes

 

Site Home

Top

Unit Home

ADR 2002