top of page

CIS043 Quiz and Solutions

CIS043 Quiz Chapter 2 Solutions

​

Question 1

1 / 1 pts

End-of-line comments that should be ignored by the compiler are denoted using

  

a.) Two forward slashes ( // ).Correct Answer

​

  

b.) Three forward slashes ( /// ).

​

  

c.) A slash and a star ( /* ).

​

  

d.) A slash and two stars (/** ).

​

​

Question 2

1 / 1 pts

Which of the following is not a valid Java identifier?

  

a.) my Variable Correct Answer

  

b.) $_Value

  

c.) widthValue

  

d.) my_variable

 

Question 3

1 / 1 pts

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.Correct Answer

​

 

Question 4

1 / 1 pts

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!" );Correct Answer

  

d.) System.out.println( Hello world! );

​

Question 5

1 / 1 pts

Which command compiles the Java source code file Welcome.java?

  

a.) cd Welcome.java

  

b.) javac Welcome.java Correct Answer

  

c.) java Welcome.java

  

d.) compile Welcome.java

​

Question 6

1 / 1 pts

Which command executes the Java class file Welcome.class?

  

a.) javac Welcome.class

  

b.) java Welcome.class Correct Answer

  

c.) java Welcome

  

d.) run Welcome.class

​

Question 7

1 / 1 pts

Which is the output of the following statements?
     System.out.print("Hello ");

     System.out.print("World");

  

a.) Hello World Correct Answer

  

b.) HelloWorld

  

c.) Hello
World

  

d.) World
Hello

​

Question 8

1 / 1 pts

Which of the following characters is the escape character?

  

a.) *

  

b.) \ Correct Answer

  

c.) \n

  

d.) "

​

Question 9

1 / 1 pts

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" ); Correct Answer
     System.out.println( " there" ); 

​

Question 10

1 / 1 pts

When method printf requires multiple arguments, the arguments are separated with ________.

  

a.) colons (:)

​

  

b.) semicolons (;)

​

  

c.) commas (,) Correct Answer

​

  

d.) periods (.)

​

​

Question 11

1 / 1 pts

Which of the following statement displays Hello World?

  

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

  

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

  

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

  

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

​

Question 12

1 / 1 pts

All import declarations must be placed

  

a.) inside the class declaration's body.

  

b.) before the class declaration. Correct Answer

​

  

c.) after the class declaration.

​

  

d.) all of these will work.

​

​

Question 13

1 / 1 pts

Which of the following is a variable declaration statement?

  

a.) int total; Correct Answer

  

b.) import java.util.Scanner;

  

c.) public static void main( String args[] )

  

d.) // first string entered by user

​

Question 14

1 / 1 pts

A(n) ________ enables a program to read data from the user.

  

a.) printf

  

c.) import declaration

  

b.) Scanner Correct Answer

  

d.) main

​

Question 15

1 / 1 pts

Which of the following is not a Java primitive type?

  

a.) char

  

b.) byte Correct Answer

  

c.) real

  

d.) double

​

Question 16

1 / 1 pts

The format specifier ________ is a place-holder for an int value?

  

a.) %a

  

b.) %d Correct Answer

  

c.) %int

  

d.) %s

​

Question 17

1 / 1 pts

What is the value of result after the following Java statements execute?
int a, b, c, d, result;
a = 4;
b = 12;
c = 38;
d = 51;
result = d % a * c/4 + (a/b - d/2); 

​

  

a.) 7

​

  

b.) 53

​

  

c.) 2

​

  

d.) 3 Correct Answer

​

​

Question 18

1 / 1 pts

Which of the following is not an arithmetic operator?

  

a.) +

​

  

b.) - Correct Answer

​

  

c.) .

​

  

d.) %

​

​

Question 19

1 / 1 pts

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 Correct Answer
      c != d

  

b.)  a < b
     d <= c 
     c != d 

  

c.) a > b 
     c != d

  

d.) a < b
     c < d 
     a != b

​

Question 20

1 / 1 pts

Each of the following is a relational or equality operator except:

  

a.) <=

  

b.) =! Correct Answer

​

  

c.) ==

​

  

d.) > 

bottom of page