Java Programming

SEQUENCE STATEMENTS MULTIPLE CHOICE QUESTIONS

1

What is a sequence statement in programming?

A.

A statement that jumps to different parts of code randomly

B.

A statement that repeats code based on a condition

C.

A statement executed in a sequential manner, one after another, in the order they appear

D.

A statement used exclusively to handle runtime exceptions

2

Which built-in Java class and method are used to capture floating-point user input?

A.

Scanner using nextFloat()

B.

BufferedReader using readLine()

C.

ConsoleInput using getFloat()

D.

JOptionPane using inputFloat()

3

How is a constant (such as PI = 3.142) properly defined in Java

A.

#define PI 3.142

B.

constant float PI = 3.142;

C.

final float PI = 3.142;

D.

const PI = 3.142;

4

What operator does Java use to combine text strings and variable values inside a System.out.println() statement?

A.

The comma (,) operator

B.

The plus (+) operator

C.

The dot (.) operator

D.

The arrow (->) operator

5

In what order must the steps be executed to properly get input from a user in Java?

A.

1. Getting the value (cin), 2. Declaring variables, 3. Instructing the user

B.

1. Instructing the user, 2. Getting the value, 3. Declaring variables

C.

1. Declaration(s), 2. Instructing the user (print), 3. Getting the value (Scanner)

D.

Order does not matter as long as the compiler runs

6

Which Scanner method should you call to read an integer value from the user?

A.

nextInteger()

B.

nextInt()

C.

readInt()

D.

getInteger()

7

What is the key difference between scanner.next() and scanner.nextLine()?

A.

next() reads a full line of text, while nextLine() only reads a single word.

B.

next() reads a single word or token up to the first space, while nextLine() reads an entire line of text including spaces.

C.

next() is used for numbers, and nextLine() is used for booleans.

D.

There is no functional difference between the two methods.

8

If you want to read a single-precision decimal number (float) from the user, which method do you use?

A.

nextDecimal()

B.

nextFloat()

C.

nextNumber()

D.

nextReal()

9

Which Scanner method is used to read a boolean value (true or false)?

A.

nextBool()

B.

nextBoolean()

C.

readBoolean()

D.

getBoolean()