NEW
Font size
WorksheetsCh 3 Java Review-Strings and Math
Total questions: 21
Worksheet time: 12mins
double num = Math.pow(2, 5);
32
double num = Math.sqrt(49);
double num = Math.floor(123.75);
double num = Math.ceil(45.17);
double num = Math.abs(-1.28);
double num = Math.max(100, 200);
200
double num = Math.min(100,200);
What is word.length()?
What is word.charAt(7) ?
What is word.indexOf(“f”)?
What is word.indexOf(“bad”)?
What is word.substring(3, 7) ?
Which of the following is NOT a primitive data type?
double
float
boolean
String
Which of these will store a decimal number?
double
single
int
String
What would be output by the following program segment?
String n1 = "Samuel";
String n2 = "Samantha";
System.out.print(n1.compareTo(n2);
false
true
a positive number, 20
a negative number, -20
Which method to use to find length of a string?
length()
size()
long()
count()
Which data type gets returned from length() method in String class?
double
String
int
number
String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
What is the correct way to find the length of "txt" string?
int len = length(txt);
float len = txt.length();
int len = txt.length();
double len = length(txt);
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));
Guess the output.
John.concat(Doe)
John Doe
JohnDoe
"John Doe"
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
What is the output?
1020
10 20
30
"10 20"
