Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||
a)+
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);
The Logical (boolean) operators are
And , or , Not
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
What is the number of iterations in the following loop:
for (int i = 1; i < n; i++) {
// iteration
}
n-1
Which of this method of class String is used to obtain a length of String object?
length()
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
what data types Equality and inequality relational operators can compare ?
primitive data values and
reference data values.
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
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
String s1 = "abc";
String s2 = "def"; System.out.println(s1.compareTo(s2));
-3
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
What is printed by the following program segment?
!(true && true || false)
false
Which expression is the same as (a == b) ?
1) ! (a != b)
2) ! (a >= b)
3) ! (a < b)
4) ! (b >= a)
! (a != b)
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
What is the default value of String variable?
A - ""
B - ''
C - null
D - not define
null
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
Given
String str1, str2;
What does str1 < str2 compare?
The addresses of the strings
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
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
String s = "Java String Quiz"; System.out.println(s.charAt(s.toUpperCase().length()));
Runtime Exception
Reference data types can only store
memory address references
(3 > 7) || ((10 < 9) == (3 == 8))
true
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
Fix the code to print number between 1 ... 10
int count = 1;
while (count < 11)
System.out.println("Count is: " + count);
count++;
Add brackets