Java Test 1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The "less than or equal to" comparison operator in Java is ________

<=

____________ is the Java assignment operator

=

What is the output from System.out.println((int)Math.random( ) * 4)? A. 0 B. 1 C. 2 D. 3 E. 4

A

What is the output of System.out.println('z' - 'a')? A. 25 B. 26 C. a D. z

A

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

A

Which of the following statements is correct? A. Every line in a program must end with a semicolon. B. Every statement in a program must end with a semicolon. C. Every comment line must end with a semicolon. D. Every method must end with a semicolon. E. Every class must end with a semicolon.

B

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

B

Which of the following is incorrect? A. int x = 9; B. long x = 9; C. float x = 1.0; D. double x = 1.0;

C

Which of the following is not permanent storage devices? A) floppy disk B) hard disk C) flash stick D) CD-ROM E) main memory

E

Which of the following operators are right-associative. A. * B. + (binary +) C. % D. && E. =

E

________ is the physical aspect of the computer that can be seen.

Hardware

Are the following four statements equivalent? number += 1; number = number + 1; number++; ++number;

Yes

To assign a value 1 to variable x, you write

x = 1;

24 % 5 is ____

4

Math.asin(0.5) returns _______. A. 30 B. Math.toRadians(30) C. Math.PI / 4 D. Math.PI / 2

B Math.asin returns an angle in radians

According to Java naming convention, which of the following names can be variables? A. FindArea B. findArea C. totalLength D. TOTAL_LENGTH E. class

B and C

An int variable can hold __________. A. 'x' B. 120 C. 120.0 D. "x" E. "120"

A and B

Which of the following are correct ways to declare variables? A. int length; int width; B. int length, width; C. int length; width; D. int length, int width;

A and B

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

A and B

Which of the following are so called short-circuit operators? A. && B. & C. || D. |

A and C

Which of the following is equivalent to x != y? A. ! (x == y) B. x > y && x < y C. x > y || x < y D. x >= y || x <= y

A and C

Suppose Character x = new Character('a'), __________________ returns true. multiple A. x.equals(new Character('a')) B. x.compareToIgnoreCase('A') C. x.equalsIgnoreCase('A') D. x.equals('a') E. x.equals("a")

A and D

Which of the following are correct names for variables according to Java naming conventions? A. radius B. Radius C. RADIUS D. findArea E. FindArea

A and D

Which of the following is a constant, according to Java naming conventions? A. MAX_VALUE B. Test C. read D. ReadInt E. COUNT

A and E

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

A and E

___________ translates high-level language program into machine language program

A compiler

Every statement in Java ends with ________

A semicolon ( ; )

To check if a string s contains the prefix "Java", you may write 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') ...

A, B, C and D

Which of the following are valid specifiers for the printf statement? A. %4c B. %10b C. %6d D. %8.2d E. %10.2e

A, B, C and E

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

A, B, C, and D

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is correct? I: if (age < 16) System.out.println("Cannot get a driver's license"); if (age >= 16) System.out.println("Can get a driver's license"); II: if (age < 16) System.out.println("Cannot get a driver's license"); else System.out.println("Can get a driver's license"); III: if (age < 16) System.out.println("Cannot get a driver's license"); else if (age >= 16) System.out.println("Can get a driver's license"); IV: if (age < 16) System.out.println("Cannot get a driver's license"); else if (age > 16) System.out.println("Can get a driver's license"); else if (age == 16) System.out.println("Can get a driver's license"); A. I B. II C. III D. IV

A, B, C, and D

What is the possible output from System.out.println((int)(Math.random( ) * 4))? A. 0 B. 1 C. 2 D. 3 E. 4

A, B, C, and D

Which of the following are the reserved words? A. public B. static C. void D. class

A, B, C, and D

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, B, C, and D

Which of the following statements are true? A. (x > 0 && x < 10) is same as ((x > 0) && (x < 10)) B. (x > 0 || x < 10) is same as ((x > 0) || (x < 10)) C. (x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0)) D. (x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) && y < 0

A, B, and C

To check if a string s contains the suffix "Java", you may write 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 and E

Which of the Boolean expressions below is incorrect? A. (true) && (3 => 4) B. !(x > 0) && (x > 0) C. (x > 0) || (x < 0) D. (x != 0) || (x = 0) E. (-10 < x < 0)

A, D, and E

____________ seeks to analyze the data flow and to identify the system?s input and output. When you do analysis, it helps to identify what the output is first, and then figure out what input data you need in order to produce the output A. Requirements specification B. Analysis C. Design D. Implementation E. Testing

Analysis

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

B

'3' - '2' + 'm' / 'n' is ______. A. 0 B. 1 C. 2 D. 3

B

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

B

Analyze the following code. boolean even = false; if (even) { System.out.println("It is even!"); } A. The code displays It is even! B. The code displays nothing. C. The code is wrong. You should replace if (even) with if (even == true). D. The code is wrong. You should replace if (even) with if (even = true)

B

Assume x = 4 and y = 5, which of the following is true? A. !(x == 4) ^ y != 5 B. x != 4 ^ y == 5 C. x == 5 ^ y == 4 D. x != 5 ^ y != 4

B

Assume x = 4 and y = 5, which of the following is true? A. x < 5 && y < 5 B. x < 5 || y < 5 C. x > 5 && y > 5 D. x > 5 || y > 5

B

Given |x - 2| >= 4, which of the following is true? A. x - 2 >= 4 && x - 2 <= -4 B. x - 2 >= 4 || x - 2 <= -4 C. x - 2 >= 4 && x - 2 < -4 D. x - 2 >= 4 || x - 2 < -4

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

Suppose income is 4001, what is the output of the following code? if (income > 3000) { System.out.println("Income is greater than 3000"); } else if (income > 4000) { System.out.println("Income is greater than 4000"); } A. no output B. Income is greater than 3000 C. Income is greater than 3000 followed by Income is greater than 4000 D. Income is greater than 4000 E. Income is greater than 4000 followed by Income is greater than 3000

B

Suppose x = 1, y = -1, and z = 1. What is the output of the following statement? (Please indent the statement correctly first.) if (x > 0) if (y > 0) System.out.println("x > 0 and y > 0"); else if (z > 0) System.out.println("x < 0 and z > 0"); A. x > 0 and y > 0; B. x < 0 and z > 0; C. x < 0 and z < 0; D. no output

B

Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x++ > 10). A. 9 B. 10 C. 11

B

Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)? A. 9 B. 10 C. 11

B

Suppose x=10 and y=10. What is x after evaluating the expression (y >= 10) || (x++ > 10). A. 9 B. 10 C. 11

B

Suppose x=10 and y=10. What is x after evaluating the expression (y >= 10) || (x-- > 10). A. 9 B. 10 C. 11

B

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is the best? I: if (age < 16) System.out.println("Cannot get a driver's license"); if (age >= 16) System.out.println("Can get a driver's license"); II: if (age < 16) System.out.println("Cannot get a driver's license"); else System.out.println("Can get a driver's license"); III: if (age < 16) System.out.println("Cannot get a driver's license"); else if (age >= 16) System.out.println("Can get a driver's license"); IV: if (age < 16) System.out.println("Cannot get a driver's license"); else if (age > 16) System.out.println("Can get a driver's license"); else if (age == 16) System.out.println("Can get a driver's license"); A. I B. II C. III D. IV

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

The expression (int)(76.0252175 * 100) / 100 evaluates to _________. A. 76.02 B. 76 C. 76.0252175 D. 76.03

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

To obtain the sine of 35 degrees, use _______. A. Math.sin(35) B. Math.sin(Math.toRadians(35)) C. Math.sin(Math.toDegrees(35)) D. Math.sin(Math.toRadian(35)) E. Math.sin(Math.toDegree(35))

B

What is the output of the following code? boolean even = false; System.out.println((even ? "true" : "false")); A. true B. false C. nothing D. true false

B

What is the output of the following code? int x = 0; if (x < 4) { x = x + 1; } System.out.println("x is " + x); A. x is 0 B. x is 1 C. x is 2 D. x is 3 E. x is 4

B

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

B

What is x after the following statements? int x = 1; x *= x + 1; A. x is 1. B. x is 2. C. x is 3. D. x is 4.

B

What is y after the following switch statement is executed? int x = 3; int y = 4; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; } A. 1 B. 2 C. 3 D. 4 E. 0

B

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

Which of the following expression results in 45.37? A. (int)(45.378 * 100) / 100 B. (int)(45.378 * 100) / 100.0 C. (int)(45.378 * 100 / 100) D. (int)(45.378) * 100 / 100.0

B

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? A. 1 < x < 100 && x < 0 B. ((x < 100) && (x > 1)) || (x < 0) C. ((x < 100) && (x > 1)) && (x < 0) D. (1 > x > 100) || (x < 0)

B

Which of the following statement prints smith\exam1\test.txt? A. System.out.println("smith\exam1\test.txt"); B. System.out.println("smith\\exam1\\test.txt"); C. System.out.println("smith\"exam1\"test.txt"); D. System.out.println("smith"\exam1"\test.txt");

B

Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4) A. (A) and (B) are the same B. (A) and (C) are the same C. (B) and (C) are the same D. (A), (B), and (C) are the same

B

Which of the following statements is correct to display Welcome to Java on the console? A. System.out.println('Welcome to Java'); B. System.out.println("Welcome to Java"); C. System.println('Welcome to Java'); D. System.out.println('Welcome to Java"); E. System.out.println("Welcome to Java');

B

Which of the following is a possible output from invoking Math.random()? A. 3.43 B. 0.5 C. 0.0 D. 1.0

B and C Math.random( ) returns a real value between 0.0 and 1.0, excluding 1.0

To add a value 1 to variable x, you write: A. 1 + x = x; B. x += 1; C. x := 1; D. x = x + 1; E. x = 1 + x;

B, D, and E

Which of the following expressions will yield 0.5? A. 1 / 2 B. 1.0 / 2 C. (double) (1 / 2) D. (double) 1 / 2 E. 1 / 2.0

B, D, and E

Why do computers use zeros and ones?

Because digital devices have two stable states and it is natural to use one state for 0 and the other for 1

A block is enclosed inside __________

Braces

Analyze the following code: int i = 3434; double d = 3434; System.out.printf("%5.1f %5.1f", i, d); A. The code compiles and runs fine to display 3434.0 3434.0. B. The code compiles and runs fine to display 3434 3434.0. C. i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.

C

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

Analyze the following program fragment: int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; } A. The program has a compile error because the required break statement is missing in the switch statement. B. The program has a compile error because the required default case is missing in the switch statement. C. The switch control variable cannot be double. D. No errors.

C

Given |x - 2| <= 4, which of the following is true? A. x - 2 <= 4 && x - 2 >= 4 B. x - 2 <= 4 && x - 2 > -4 C. x - 2 <= 4 && x - 2 >= -4 D. x - 2 <= 4 || x - 2 >= -4

C

Math.cos(Math.PI) returns _______. A. 0.0 B. 1.0 C. -1.0 D. 0.5

C

Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true. A. if (isPrime = true) B. if (isPrime == true) C. if (isPrime) D. if (!isPrime = false) E. if (!isPrime == false)

C

Suppose s is a string with the value "java". What will be assigned to x if you execute the following code? char x = s.charAt(4); A. 'a' B. 'v' C. Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException.

C

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

C

The JDK command to compile a class in the file Test.java is: A. java Test B. java Test.java C. javac Test.java D. javac Test E. JAVAC Test.java

C

The __________ method immediately terminates the program. A. System.terminate(0); B. System.halt(0); C. System.exit(0); D. System.quit(0); E. System.stop(0);

C

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

C

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"); A. too hot B. too cold C. just right D. too hot too cold just right

C

The main method header is written as: A. public static void main(string[ ] args) B. public static void Main(String[ ] args) C. public static void main(String[ ] args) D. public static main(String[ ] args) E. public void main(String[ ] args)

C

The order of the precedence (from high to low) of the operators binary +, *, &&, ||, ^ is: A. &&, ||, ^, *, + B. *, +, &&, ||, ^ C. *, +, ^, &&, || D. *, +, ^, ||, && E. ^, ||, &&, *, +

C

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

C

To obtain the current second, use _________. A. System.currentTimeMillis() % 3600 B. System.currentTimeMillis() % 60 C. System.currentTimeMillis() / 1000 % 60 D. System.currentTimeMillis() / 1000 / 60 % 60 E. System.currentTimeMillis() / 1000 / 60 / 60 % 24

C

What is 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

What is y displayed in the following code? 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

C

What is y displayed in the following code? public class Test1 { public static void main(String[] args) { int x = 1; int y = x = x + 1; System.out.println("y is " + y); } } A. y is 0. B. y is 1 because x is assigned to y first. C. y is 2 because x + 1 is assigned to x and then x is assigned to y. D. The program has a compile error since x is redeclared in the statement int y = x = x + 1

C

Which of the following code displays the area of a circle if the radius is positive. A. if (radius != 0) System.out.println(radius * radius * 3.14159); B. if (radius >= 0) System.out.println(radius * radius * 3.14159); C. if (radius > 0) System.out.println(radius * radius * 3.14159); D. if (radius <= 0) System.out.println(radius * radius * 3.14159);

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

________ is not an object-oriented programming language A) Java B) C++ C) C D) C# E) Python

C

____________ is an operating system A) Java B) C++ C) Windows D) Visual Basic E) Ada

C

What is Math.ceil(3.6)? A. 3.0 B. 3 C. 4.0 D. 5.0

C Note ceil returns double value

What is Math.rint(3.6)? A. 3.0 B. 3 C. 4.0 D. 5.0

C Note rint returns a double value

What is Math.round(3.6)? A. 3.0 B. 3 C. 4 D. 4.0

C Note round returns an int value

What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5? A. true B. false C. There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true

C Since the expression involves floating-point numbers and floating-point numbers are approximated

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 When a sting adds with a number, the number is converted to a string

Programming style is important, because ______________. A. a program may not compile if it has a bad style B. good programming style can make a program run faster C. good programming style makes a program more readable D. good programming style helps reduce programming errors

C and D

Which of the following assignment statements is incorrect? A. i = j = k = 1; B. i = 1; j = 1; k = 1; C. i = 1 = j = 1 = k = 1; D. i == j == k == 1;

C and D

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

C and E

Which of the following lines is not a Java comment? A. /*** comments **/ B. // comments C. -- comments D. /** comments **/ E. ** comments **

C and E

____________________ returns true. multiple A. "peter".compareToIgnoreCase("Peter") B. "peter".compareToIgnoreCase("peter") C. "peter".equalsIgnoreCase("Peter") D. "peter".equalsIgnoreCase("peter") E. "peter".equals("peter")

C, D, and E

________ is the brain of the computer

CPU

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

D

Analyze the following code. I: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } II: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } A. Both I and II can compile and run and display Welcome to Java, but the code in II has a better style than I. B. Only the code in I can compile and run and display Welcome to Java. C. Only the code in II can compile and run and display Welcome to Java. D. Both I and II can compile and run and display Welcome to Java, but the code in I has a better style than II.

D

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

Analyze the following code: Code 1: int number = 45; boolean even; if (number % 2 == 0) even = true; else even = false; Code 2: int number = 45; boolean even = (number % 2 == 0); A. Code 1 has compile errors. B. Code 2 has compile errors. C. Both Code 1 and Code 2 have compile errors. D. Both Code 1 and Code 2 are correct, but Code 2 is better

D

Analyze the following code: boolean even = false; if (even = true) { System.out.println("It is even"); } A. The program has a compile error. B. The program has a runtime error. C. The program runs fine, but displays nothing. D. The program runs fine and displays It is even.

D

Assume x = 4, which of the following is true? A. !(x == 4) B. x != 4 C. x == 5 D. x != 5

D

Suppose x is 1. What is x after x += 2? A. 0 B. 1 C. 2 D. 3 E. 4

D

The Unicode of 'a' is 97. What is the Unicode for 'c'? A. 96 B. 97 C. 98 D. 99

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 following code fragment reads in two numbers: Scanner input = new Scanner(System.in); int i = input.nextInt(); double d = input.nextDouble(); What is the incorrect way 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.

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

To assign a double variable d to a float variable x, you write A. x = (long)d B. x = (int)d; C. x = d; D. x = (float)d;

D

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

To obtain the current minute, use _________. A. System.currentTimeMillis() % 3600 B. System.currentTimeMillis() % 60 C. System.currentTimeMillis() / 1000 % 60 D. System.currentTimeMillis() / 1000 / 60 % 60 E. System.currentTimeMillis() / 1000 / 60 / 60 % 24

D

What is 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

What is the output of the following code: double x = 5.5; int y = (int)x; System.out.println("x is " + x + " and y is " + y); A. x is 5 and y is 6 B. x is 6.0 and y is 6.0 C. x is 6 and y is 6 D. x is 5.5 and y is 5 E. x is 5.5 and y is 5.0

D

What is x after the following statements? 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

Which of the following expression results in a value 1? A. 2 % 1 B. 15 % 4 C. 25 % 5 D. 37 % 6

D

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

D

What is Math.rint(3.5)? A. 3.0 B. 3 C. 4 D. 4.0 E. 5.0

D Note rint returns nearest even int as a double since 3.5 is equally close to 3.0 and 4.0

To add number to sum, you write (Note: Java is case-sensitive) A. number += sum; B. number = sum + number; C. sum = Number + sum; D. sum += number; E. sum = sum + number;

D and E

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

D and E

Analyze the following code fragments that assign a boolean value to the variable even. Code 1: if (number % 2 == 0) even = true; else even = false; Code 2: even = (number % 2 == 0) ? true: false; Code 3: even = number % 2 == 0; A. Code 2 has a compile error, because you cannot have true and false literals in the conditional expression. B. Code 3 has a compile error, because you attempt to assign number to even. C. All three are correct, but Code 1 is preferred. D. All three are correct, but Code 2 is preferred. E. All three are correct, but Code 3 is preferred.

E

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 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 current hour in UTC, use _________. A. System.currentTimeMillis() % 3600 B. System.currentTimeMillis() % 60 C. System.currentTimeMillis() / 1000 % 60 D. System.currentTimeMillis() / 1000 / 60 % 60 E. System.currentTimeMillis() / 1000 / 60 / 60 % 24

E

-24 % -5 is ____

-4

-24 % 5 is ____

-4

The extension name of a Java bytecode file is .java .obj .class .exe

.class

The extension name of a Java source code file is

.java

-25 % 5 is ____

0

25 % 1 is ____

0

Math.pow(4, 1 / 2) returns ________

1.0 Note that 1 / 2 is 0

What is the result of 45 / 4?

11

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); } }

2.0

Math.pow(4, 1.0 / 2) returns _____

2.0

what is the value of (double)(5/2)?

2.0

What is the value of (double)5/2?

2.5

The expression 4 + 20 / (3 - 1) * 2 is evaluated to

24

One byte has ________ bits

8 bits

Math.pow(2, 3) returns _______

8.0

The equal comparison operator in Java is _______

==

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

A

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

A

Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read a real number? A. input.nextDouble(); B. input.nextdouble(); C. input.double(); D. input.Double()

A

Suppose s1 and s2 are two strings. What is the result of the following code? s1.equals(s2) == s2.equals(s1) A. true B. false

A

Suppose x is 1. What is x after x -= 1? A. 0 B. 1 C. 2 D. -1 E. -2

A

To obtain the arc sine of 0.5, use _______. A. Math.asin(0.5) B. Math.asin(Math.toDegrees(0.5)) C. Math.sin(Math.toRadians(0.5)) D. Math.sin(0.5)

A

What is 1 + 1 + 1 + 1 + 1 == 5? A. true B. false C. There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.

A

What is the value of the following expression? true || true && false A. true B. false

A

What is y after the following statement is executed? x = 0; y = (x > 0) ? 10 : -10; A. -10 B. 0 C. 10 D. 20 E. Illegal expression

A

Which JDK command is correct to run a Java application in ByteCode.class? A. java ByteCode B. java ByteCode.class C. javac ByteCode.java D. javac ByteCode E. JAVAC ByteCode

A

Which of these data types requires the most amount of memory? A. long B. int C. short D. byte

A

_______ is architecture-neutral A) Java B) C++ C) C D) Ada E) Pascal

A

________ is interpreted A) Java B) C++ C) C D) Ada E) Pascal

A

What is Math.floor(3.6)? A. 3.0 B. 3 C. 4 D. 5.0

A Note floor returns double value

Math.sin(Math.PI) returns _______. A. 0.0 B. 1.0 C. 0.5 D. 0.4

A Note that Math.PI is 180 degrees

If you attempt to add an int, a byte, a long, and a double, the result will be a __________ value

double

To declare an int variable number with initial value 2, you write

int number = 2;

Computer can execute the code in ____________ A. Machine language B. Assembly Language C. High-level language D. None of the above

machine language

The speed of the CPU may be measured in __________

megahertz and gigahertz

When assigning a literal to a variable of the byte type, if the literal is too large to be stored as a byte value, it ____________ causes overflow causes underflow causes no error cannot happen in Java receives a compile error

receives a compile error

Which of the following code has the best style? I: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } II: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } III: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } IV: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }

IV

________ contains predefined classes and interfaces for developing Java programs

Java API

_______ provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface

Java IDE

_______ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line

Java JDK

_______ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line Java language specification Java API Java JDK Java IDE

Java JDK

Java compiler translates Java source code into ________ a. java bytecode b. machine code c. assembly code d. another high-level language code

Java bytecode

________ is a technical definition of the language that includes the syntax and semantics of the Java programming language

Java language specification

_________ is a software that interprets Java bytecode A. Java virtual machine B. Java compiler C. Java debugger D. Java API

Java virtual machine

How do you write 2.5 ^ 3.1 in Java?

Math.pow(2.5, 3.1)

The __________ method returns a raised to the power of b

Math.pow(a, b)

____________ is a device to connect a computer to a local area network (LAN)

Network Interface Card (NIC)

_____________ is a program that runs on a computer to manage and control a computer's activities

Operating system

______ is the code with natural language mixed with Java code

Pseudocode

_____________ 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

Requirements specification

____________ are instructions to the computer multiple hardware software programs keywords

Software and Programs

Java was developed by ____________

Sun Microsystems

Suppose you define a Java class as follows: public class Test { } In order to compile this program, the source code should be stored in a file named ____________

Test.java

In Java, the word true is _______

a Boolean literal

If you forget to put a closing quotation mark on a string, what kind of error will be raised? a compile error a runtime error a logic error

a compile error

If a program compiles fine, but it produces incorrect result, then the program suffers _________

a logic error

Due to security reasons, Java ___________ cannot run from a Web browser in the new version of Java applications applets servlets Micro Edition programs

applets

What is the exact output of the following code? double area = 3.5; System.out.print("area"); System.out.print(area);

area3.5

To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159

constants


संबंधित स्टडी सेट्स

Chapter 14: General Surgery; Short Answer: Instrumentation

View Set

MindTap: Worksheet 12.2: Consideration

View Set

Chapter 60: Assessment of Integumentary Function

View Set

AP Statistics Unit 5 Progress Check: MCQ Part B

View Set

CFA_L1_Assignment_141_Lesson 2: Risk Aversion, Portfolio Selection and Portfolio Risk

View Set