JAVA Chapter 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is a valid identifier? A. $343 B. class C. 9X D. 8+9 E. radius

A. $343 E. radius

Which of the following are the same as 1545.534? A. 1.545534e+3 B. 0.1545534e+4 C. 1545534.0e-3 D. 154553.4e-2

A. 1.545534e+3 B. 0.1545534e+4 C. 1545534.0e-3 D. 154553.4e-2

The following code fragment reads in two numbers: Scanner input = new Scanner(System.in); int i = input.nextInt(); double d = input.nextDouble(); What are the correct ways to enter these two numbers? A. Enter an integer, a space, a double value, and then the Enter key. B. Enter an integer, two spaces, a double value, and then the Enter key. C. Enter an integer, an Enter key, a double value, and then the Enter key. D. Enter a numeric value with a decimal point, a space, an integer, and then the Enter key.

A. Enter an integer, a space, a double value, and then the Enter key. B. Enter an integer, two spaces, a double value, and then the Enter key. C. Enter an integer, an Enter key, a double value, and then the Enter key.

_____________ is a formal process that seeks to understand the problem and document in detail what the software system needs to do. A. Requirements specification B. Analysis C. Design D. Implementation E. Testing

A. Requirements specification

Which of the following assignment statements is correct? A. char c = 'd'; B. char c = 100; C. char c = "d"; D. char c = "100";

A. char c = 'd'; B. char c = 100;

Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read an int value? A. input.nextInt(); B. input.nextInteger(); C. input.int(); D. input.integer();

A. input.nextInt();

Every letter in a Java keyword is in lowercase? A. true B. false

A. true

If you enter 1 2 3, when you run this program, what will be the output? import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter three numbers: "); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble(); // Compute average double average = (number1 + number2 + number3) / 3; // Display result System.out.println(average); } } A. 1.0 B. 2.0 C. 3.0 D. 4.0

B. 2.0

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. Integer.parseInt(s);

Will System.out.println((char)4) display 4? A. Yes B. No

B. No Explanation: The Unicode is to be displayed, not number 4.

The __________ method displays an input dialog for reading a string. A. String string = JOptionPane.showMessageDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); B. String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); C. String string = JOptionPane.showInputDialog("Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); D. String string = JOptionPane.showInputDialog(null, "Enter a string"); E. String string = JOptionPane.showInputDialog("Enter a string");

B. String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); D. String string = JOptionPane.showInputDialog(null, "Enter a string"); E. String string = JOptionPane.showInputDialog("Enter a string");

_____________ seeks to analyze the data flow and to identify the system's input and output. A. Requirements specification B. System analysis C. Design D. Implementation E. Testing

B. System analysis

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. System.out.println((char)i);

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

B. two bytes

What is y displayed? public class Test { public static void main(String[] args) { int x = 1; int y = x + x++; System.out.println("y is " + y); } } A. y is 1. B. y is 2. C. y is 3. D. y is 4.

B. y is 2. Explanation: When evaluating x + x++, x is evaluated first, which is 1. X++ returns 1 since it is post-increment and 2. Therefore y is 1 + 1.

What is the value of i printed in the following code? public class Test { public static void main(String[] args) { int j = 0; int i = j++ + j * 5; System.out.println("What is i? " + i); } } A. 0 B. 1 C. 5 D. 6

C. 5

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

C. Java 123

_______ is the code with natural language mixed with Java code. A. Java program B. A Java statement C. Pseudocode D. A flowchart diagram

C. Pseudocode

To declare a constant MAX_LENGTH inside a method with value 99.98, you write A. final MAX_LENGTH = 99.98; B. final float MAX_LENGTH = 99.98; C. double MAX_LENGTH = 99.98; D. final double MAX_LENGTH = 99.98;

D. final double MAX_LENGTH = 99.98;

Analyze the following code: public class Test { public static void main(String[] args) { int n = 10000 * 10000 * 10000; System.out.println("n is " + n); } } A. The program displays n is 1000000000000 B. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program is aborted. C. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program continues to execute because Java does not report errors on overflow. D. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an underflow and the program is aborted. E. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an underflow and the program continues to execute because Java does not report errors on underflow.

C. The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program continues to execute because Java does not report errors on overflow.

Suppose x is a char variable with a value 'b'. What will be displayed by the statement System.out.println(++x)? A. a B. b C. c D. d

C. c

To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159. A. variables B. methods C. constants D. classes

C. constants

-24 % -5 is _____ A. 3 B. -3 C. 4 D. -4 E. 0

D. -4

Math.pow(4, 1 / 2) returns __________. A. 2 B. 2.0 C. 0 D. 1.0 E. 1

D. 1.0

What is the value of i printed? public class Test { public static void main(String[] args) { int j = 0; int i = ++j + j * 5; System.out.println("What is i? " + i); } } A. 0 B. 1 C. 5 D. 6

D. 6

Math.pow(2, 3) returns __________. A. 9 B. 8 C. 9.0 D. 8.0

D. 8.0

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. Double.parseDouble(s);

Analyze the following code. public class Test { public static void main(String[] args) { int month = 09; System.out.println("month is " + month); } } A. The program displays month is 09 B. The program displays month is 9 C. The program displays month is 9.0 D. The program has a syntax error, because 09 is an incorrect literal value.

D. The program has a syntax error, because 09 is an incorrect literal value.

If you attempt to add an int, a byte, a long, and a double, the result will be a __________ value. A. byte B. int C. long D. double

D. double

Which of the following assignment statements is illegal? A. float f = -34; B. int t = 23; C. short s = 10; D. int t = (int)false; E. int t = 4.5;

D. int t = (int)false; E. int t = 4.5;

int x = 2; int y = 1; x *= y + 1; A. x is 1. B. x is 2. C. x is 3. D. x is 4.

D. x is 4.

The System.currentTimeMillis() returns ________________ . A. the current time. B. the current time in milliseconds. C. the current time in milliseconds since midnight. D. the current time in milliseconds since midnight, January 1, 1970. E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).

E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).


Set pelajaran terkait

Adobe Photoshop Digital Imaging Midterm

View Set

AP Government Test Bank Questions Chapters 1-20

View Set

Advanced Patho/Pharm: Integumentary Medications Saunders ?'s

View Set