Java Chapter Four Test

¡Supera tus tareas y exámenes ahora con Quizwiz!

Math.cos(Math.PI) returns _______.

-1.0

"abc".compareTo("aba") returns ___________. A. 1 B. 2 C. -1 D. -2 E. 0

2

What is the output of System.out.println('z' - 'a')?

25

What is Math.floor(3.6)?

3.0

What is Math.rint(3.6)?

4.0, Explanation: Note that rint returns a double value

What is Math.rint(3.5)?

4.0, Explanation: rint returns the nearest even integer as a double since 3.5 is equally close to 3.0 and 4.0.

What is the return value of "SELECT".substring(4, 4)? A. an empty string B. C C. T D. E

A

An int variable can hold __________. Please select all that apply. A. 'x' B. 120 C. 120.0 D. "x" E. "120"

A & B

Which of the following is correct to obtain the square root of 5? Please select all that apply. A. Math.sqrt(5) B. Math.sqrt(25) C. Math.pow(5, 0.5) D. Math.pow(5, 2)

A. C.

To check if a string s contains the suffix "Java", you may write _____________. Please select all that apply. A. if (s.endsWith("Java")) ... B. if (s.lastIndexOf("Java") >= 0) ... C. if (s.substring(s.length() - 4).equals("Java")) ... D. if (s.substring(s.length() - 5).equals("Java")) ... E. if (s.charAt(s.length() - 4) == 'J' && s.charAt(s.length() - 3) == 'a' && s.charAt(s.length() - 2) == 'v' && s.charAt(s.length() - 1) == 'a') ...

A. C. E.

To check if a string s contains the prefix "Java", you may write _____________. Please select all that apply. A. if (s.startsWith("Java")) ... B. if (s.indexOf("Java") == 0) ... C. if (s.substring(0, 4).equals("Java")) ... D. if (s.charAt(0) == 'J' && s.charAt(1) == 'a' && s.charAt(2) == 'v' && s.charAt(3) == 'a') ...

All are correct

Suppose s1 and s2 are two strings. Which of the following statements or expressions is incorrect? Please select all that apply. A. String s3 = s1 - s2; B. boolean b = s1.compareTo(s2); C. char c = s1[0]; D. char c = s1.charAt(s1.length());

All are incorrect

Which of the following is correct to obtain the min of x, y, z? Please select all that apply. A. Math.min(x, Math.min(y, z)) B. Math.min(Math.min(x, y), z) C. Math.min(Math.min(y, z), x) D. Math.min(z, Math.min(x, y))

All choices are correct

A Java character is stored in __________. A. one byte B. two bytes C. three bytes D. four bytes

B

Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i? A. System.out.println(i); B. System.out.println((char)i); C. System.out.println((int)i); D. System.out.println(i + " ");

B

The __________ method parses a string s to an int value. A. integer.parseInt(s); B. Integer.parseInt(s); C. integer.parseInteger(s); D. Integer.parseInteger(s);

B

To check whether a char variable ch is an uppercase letter, you write ___________. A. (ch >= 'A' && ch >= 'Z') B. (ch >= 'A' && ch <= 'Z') C. (ch >= 'A' || ch <= 'Z') D. ('A' <= ch <= 'Z')

B

What is the return value of "SELECT".substring(0, 5)? A. "SELECT" B. "SELEC" C. "SELE" D. "ELECT"

B

Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________. A. 66 B. B C. A1 D. Illegal expression

C

The expression "Java " + 1 + 2 + 3 evaluates to ________. A. Java123 B. Java6 C. Java 123 D. java 123 E. Illegal expression

C

The statement System.out.printf("%5d", 123456) outputs ___________. A. 12345 B. 23456 C. 123456 D. 12345.6

C

Which of the following is the correct statement to return JAVA? A. toUpperCase("Java") B. "Java".toUpperCase("Java") C. "Java".toUpperCase() D. String.toUpperCase("Java")

C

Which of the following is not a correct method in the Character class? Please select all that apply. A. isLetterOrDigit(char) B. isLetter(char) C. isDigit() D. toLowerCase(char) E. toUpperCase()

C & E

____________________ returns true. Please select all that apply. A. "peter".compareToIgnoreCase("Peter") B. "peter".compareToIgnoreCase("peter") C. "peter".equalsIgnoreCase("Peter") D. "peter".equalsIgnoreCase("peter") E. "peter".equals("peter")

C. D. E.

"AbA".compareToIgnoreCase("abC") returns ___________. A. 1 B. 2 C. -1 D. -2 E. 0

D

The __________ method parses a string s to a double value. A. double.parseDouble(s); B. Double.parsedouble(s); C. double.parse(s); D. Double.parseDouble(s);

D

The statement System.out.printf("%10s", 123456) outputs ___________. (Note: * represents a space) A. 123456**** B. 23456***** C. 12345***** D. ****123456

D

The statement System.out.printf("%3.1e", 1234.56) outputs ___________. A. 0.1e+04 B. 0.123456e+04 C. 0.123e+04 D. 1.2e+03 E. 1.23+03

D

Which of the following is an invalid specifier for the printf statement? A. %4c B. %10b C. %6d D. %8.2d E. %10.2e

D

Which of the following is the correct expression of character 4? A. 4 B. "4" C. '\0004' D. '4'

D

The statement System.out.printf("%3.1f", 1234.56) outputs ___________. A. 123.4 B. 123.5 C. 1234.5 D. 1234.56 E. 1234.6

E

To obtain the arc sine of 0.5, use _______.

Math.asin(0.5)

To obtain the sine of 35 degrees, use _______.

Math.sin(Math.toDegrees(35))

Math.asin(0.5) returns _______.

Math.toRadians(30)


Conjuntos de estudio relacionados

Unit I - Review Homework & Quizzes

View Set

Chapter 7 Knowledge Representation.

View Set

Computed Tomography; Chapter. 18

View Set

PrepU - CH.1 Nurse's role in health assessment: collecting and analyzing data

View Set

MBA 6207 - Chapter 10 Knowledge Management and Specialized Information Systems

View Set