Chapter 1

Ace your homework & exams now with Quizwiz!

Q13: Which of the following is a variable declaration statement? a) int total; b) import java.util.Scanner; c) public static void main( String args[] ) d) // first string entered by user

a) int total;

Q19: List the following operators in the order that they will be evaluated: -, *, /, +, %. Assume that if two operations have the same precedence, the one listed first will be evaluated first. a) +, -, /, *, %. b) -, +, %, *, /. c) -, *, %, +, /. d) *, /, %, -, +.

d) *, /, %, -, +.

Q18: What is the value of result after the following Java statements execute? int a, b, c, d, result; a = 4; b = 12; c = 37; d = 51; result = d % a * c + a % b + a; a) 119 b) 51 c) 127 d) 59

a) 119

Q7: Which is the output of the following statements? System.out.print( "Hello "); System.out.println( "World" ); a) Hello World b) HelloWorld c) Hello World d) World Hello

a) Hello World

Q23: Each of the following is a relational or equality operator except: a) <= b) =! c) == d) >

b) =!

Q5: Which command compiles the Java source code file Welcome.java? a) cd Welcome.java b) javac Welcome.java c) java Welcome.java d) compile Welcome.java

b) javac Welcome.java

Q20: Which of the following is not an arithmetic operator? a) + b) - c) . d) %

c) .

Q22: Which of the following is not a syntax error? a) Neglecting to initialize a local variable in a method before it is used. b) Using a single equals sign instead of a double equals sign in the condition of an if statement. c) Placing a semicolon at the end of the first line of an if statement. d) Omitting the left and right parenthesis for the condition of an if statement.

c) Placing a semicolon at the end of the first line of an if statement.

Q14: A(n) ________ enables a program to read data from the user. a) printf. b) import declaration. c) Scanner. d) main.

c) Scanner.

Q3: Which of the following cannot cause a syntax error to be reported by the Java compiler? a) Mismatched {} b) Missing */ in a comment that begins with /* c) Missing ; d) Extra blank lines.

d) Extra blank lines.

Q21: What will be output after the following Java statements have been executed? int a, b, c, d; a = 4; b = 12; c = 37; d = 51; if ( a < b ) System.out.println( "a < b" ); if ( a > b ) System.out.println( "a > b" ); if ( d <= c ) System.out.println( "d <= c" ); if ( c != d ) System.out.println( "c != d" ); a) a < b c != d b) a < b d <= c c != d c) a > b c != d d) a < b c < d a != b

a) a < b c != d

Q17: Which of the following statements does not alter a memory location? a) int a; b) number = 12; c) y = y + 2; d) width = Integer.parseInt(input);

a) int a;

Q9: Which of the following statements will print a single line containing "hello there"? a) System.out.println( "hello" ); System.out.println( " there" ); b) System.out.println( "hello" , " there" ); c) System.out.println( "hello" ); System.out.print( " there" ); d) System.out.print( "hello" ); System.out.println( " there" );

d) System.out.print( "hello" ); System.out.println( " there" );

Q2: Which of the following is not a valid Java identifier? a) my Value b) $_AAA1 c) width d) m_x

a) my Value

Q16: The format specifier ________ is a place-holder for an int value? a) %a. b) %d. c) %int. d) %s.

b) %d.

Q8: Which of the following characters is the escape character? a) * b) \ c) \n d) "

b) \

Q11: Which of the following statement displays Hello World? a) System.out.printf( "%2s", "Hello " "World" ); b) System.out.printf( "%s %s", "Hello", "World" ); c) System.out.printf( "%s%s", "Hello, World" ); d) System.out.printf( "s% s%", "Hello", "World" );

b) System.out.printf( "%s %s", "Hello", "World" );

Q4: Which of the following is not a syntax error? a) System.out.println( 'Hello world!' ): b) System.out.println( "Hello world!" ); c) System.out.println( "Hello world!" ); d) System.out.println( Hello world! );

c) System.out.println( "Hello world!" );

Q10: When method printf requires multiple arguments, the arguments are separated with ________. a) colons (:). b) semicolons (;). c) commas (,). d) periods (.).

c) commas (,).

Q6: Which command executes the Java class file Welcome.class? a) javac Welcome.class b) java Welcome.class c) java Welcome d) run Welcome.class

c) java Welcome

Q15: Which of the following is not a Java primitive type? a) char b) byte c) real d) double

c) real

Q1: End-of-line comments that should be ignored by the compiler are denoted using a) Two forward slashes ( // ). b) Three forward slashes ( /// ). c) A slash and a star ( /* ). d) A slash and two starts ( /** ).

a) Two forward slashes ( // ).


Related study sets

HESI Medical-Surgical Practice Test

View Set

Nclex PN Renal and urinary practice questions

View Set

Prose Fiction Concepts and Terms

View Set

Smartbook questions (Ch1,ch2,ch3,ch4

View Set

Chapter 36: Management of Patients With Immunodeficiency Disorders

View Set