String Handling
Class and Instance Objects
Boolean Expressions
Control flow
Iteration
100

Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||

a)+

100

Which of the following statements uses

  proper syntax for a return method call?

(A)  displaySum(n1, n2);

(B)  System.out.println(getSum(int n1, int n2));

(C)  int sum = getSum(n1,n2);

(D)  displaySum(int n1, int n2);

int sum = getSum(n1,n2);

100

 The Logical (boolean) operators are

And , or , Not

100

What output is produced by the segment of code shown below 

int x = 25;
if (x == 25)
  System.out.print("BOBBA");
else
  System.out.print("FAB");

BOBBA

100

What is the number of iterations in the following loop:
 for (int i = 1; i < n; i++) {
 // iteration
 }

n-1

200

Which of this method of class String is used to obtain a length of String object?

length()

200

 Which the following statements constructs a String object correctly?

(A)String s1 = "Aardvark means dirt pig.";

(B) String s2 = new String("Hello Suzie");

(C) String s3 = new String(s2);

(D) All of the above

(D) All of the above

200

what data types Equality and inequality relational operators can compare ?


primitive data values and 

reference data values.


200

Given : a = 1, b = 2

if ( missing ) 

   print "X"

Select ALL expressions which can be used for missing to result in an "X" being printed.

1) a < 2 && b == 2

2) a != b || a == b

3) a > b

4) ! (b >= a)

5) b == a

a < 2 && b == 2

a != b || a == b

200

what is the output of the following loop?

The following loop displays _______________.
for (int i = 1; i <= 10; i++) {
 System.out.print(i + " ");
 i++;
}

1 3 5 7 9

300


String s1 = "abc";

 String s2 = "def"; System.out.println(s1.compareTo(s2));

-3

300

What is printed by the following program segment?

String s1= "1234";

String s2 =1234;

System.out.print(s1.equals(s2));

(A) true

(B) false

(C) runtime error

(D) compile error  

compile error  

300

What is printed by the following program segment?

       !(true  && true || false)


false

300

Which expression is the same as (a == b) ?

1) ! (a != b)

2) ! (a >= b)

3) ! (a < b)

4) ! (b >= a)

 

! (a != b)

300

What is the output of this code:

public class While {  

  public void loop()     { 

       int x= 0;  

      while ( 1 ) /* Line 6 */     

   {      

  System.out.print("x plus one is " + (x + 1)); 

/* Line 8 */    

    } } }

Syntax Error in line 6

400

What is the default value of String variable?

A - ""

B - ''

C - null

D - not define

null

400

What is printed by the following program segment?

int x = (int) (Math.random() *1201 +400);

System.out.print(x);

(A) A value x, such that 400 <= x <= 1200

(B) A value x, such that 400.0 < x < 1600.0

(C) A value x, such that 400 <= x <= 1600

(D) A value x, such that 0 <= x <= 1600

(C) A value x, such that 400 <= x <= 1600

400

Given

String str1, str2;

What does str1 < str2 compare?

The addresses of the strings

400

The following code displays ___________.


double temperature = 50;
if (temperature >= 100)
 System.out.println("too hot");
else if (temperature <= 40)
 System.out.println("too cold");
else
 System.out.println("just right");


just right

400

The value of count at the end of the code segment.

int count=0;

 for(int x=0; x<20; x++;){

 for(int y= x+1; x<8; x++;){

 count++; }

}

28

500


String s = "Java String Quiz"; System.out.println(s.charAt(s.toUpperCase().length()));

Runtime Exception

500

Reference data types can only store


memory address references

500

(3 > 7) || ((10 < 9) == (3 == 8))

true

500

 Assume x = 4 and y = 5, Which of the following is true? 

1) x < 5 && y < 5

2) x < 5 || y < 5

3)x > 5 && y > 5

4)x > 5 || y > 5

 x < 5 || y < 5

500

Fix the code to print number between 1 ... 10

int count = 1; 

while (count < 11) 

System.out.println("Count is: " + count); 

count++;

Add brackets

M
e
n
u