wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Ch 3 Java Review-Strings and Math

Total questions: 21

Worksheet time: 12mins

Name
Class
Date
1.
What is the value of num?
double num = Math.pow(2, 5);
a)
10.0
b)

32

c)
32.0
d)
25.0
2.
What is the value of num?
double num = Math.sqrt(49);
a)
7
b)
7.0
3.
What is the value of num?
double num = Math.floor(123.75);
a)
123.0
b)
124.0
4.
What is the value of num?
double num = Math.ceil(45.17);
a)
45.0
b)
46.0
5.
What is the value of num?
double num = Math.abs(-1.28);
a)
1.28
b)
-1.28
c)
1.3
d)
1.2
6.
What is the value of num?
double num = Math.max(100, 200);
a)
100.0
b)
200.0
c)
300.0
d)

200

7.
What is the value of num?
double num = Math.min(100,200);
a)
100.0
b)
200.0
c)
150.0
d)
300.0
8.
String word = "A few good men";
What is word.length()?
a)
14
b)
15
c)
13
9.
String word = "A few good men";
What is word.charAt(7) ?
a)
o
b)
g
c)
7
d)
good men
10.
String word = "A few good men";
What is word.indexOf(“f”)?
a)
2
b)
0
c)
1
d)
-1
11.
String word = "A few good men";
What is word.indexOf(“bad”)?
a)
0
b)
-1
c)
3
12.
String word = "A few good men";
What is word.substring(3, 7) ?
a)
ew g
b)
ew go
c)
few
d)
few[space]
13.

Which of the following is NOT a primitive data type?

a)

double

b)

float

c)

boolean

d)

String

14.

Which of these will store a decimal number?

a)

double

b)

single

c)

int

d)

String

15.

What would be output by the following program segment?


String n1 = "Samuel";

String n2 = "Samantha";


System.out.print(n1.compareTo(n2);

a)

false

b)

true

c)

a positive number, 20

d)

a negative number, -20

16.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

17.

Which data type gets returned from length() method in String class?

a)

double

b)

String

c)

int

d)

number

18.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

19.

String txt = "Hello World";

System.out.println(txt.toUpperCase());


Choose the correct output.

a)

"HELLO WORLD"

b)

HELLO WORLD

c)

Hello world

d)

Hello World

20.

String firstName = "John ";

String lastName = "Doe";

System.out.println(firstName.concat(lastName));


Guess the output.

a)

John.concat(Doe)

b)

John Doe

c)

JohnDoe

d)

"John Doe"

21.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

What is the output?

a)

1020

b)

10 20

c)

30

d)

"10 20"