stud
bud
Sign up
Log in
Home
Library
Explore
SAT
More
Java chapter 3_4 Flashcards | StudBud
Explore
/
Java chapter 3_4
Java chapter 3_4
19 terms
·
StudBud Administration
·
22 plays
Test your knowledge on the basic concepts and syntax of Java programming
Flashcards
19 cards
F
Practice quiz
P
Host live
L
Questions
19
Answers
1
Which is a loop structure in Java?
if
while
switch
boolean
2
Which is a relational operator?
+
&&
>
=
3
Condition in while loop never false?
Program crashes
Program stops
Execute indefinitely
Compilation error
4
Generate random number 1-10 in Java?
Math.random(10)
Random.nextInt(10) + 1
Random.nextInt(10)
Random(1,10)
5
Purpose of switch statement in Java?
None of the above
Create loops
Compare objects
Replace if-else
6
Purpose of an if statement in Java?
Define a method
Execute code conditionally
Declare a variable
Print output
7
Output of code: for (int i = 0; i < 3; i++) { System.out.println("Hello"); }
Prints "Hello" three times
Prints "Hello" once
Compilation error
No output
8
What is a flag variable in Java?
Special operator
Data type
Boolean condition tracker
Loop counter
9
Output of code: int x = 5; while (x > 0) { System.out.println(x); x--; }
Infinite loop
Prints 5 to 1
Prints 1 to 5
No output
10
Operator to check equality in Java?
=
==
>=
!=
11
Correct syntax for a for loop?
for (test; update; init)
for (init; test; update)
for (init test update)
for { init; test; update }
12
Output of code: int x = 5; if (x > 3) { System.out.println("Hello"); }
None of the above
Hello
Compilation error
No output
13
What is a nested if statement?
If inside another if
None of the above
Loop inside if
Method inside if
14
Case without break in switch statement?
Next case executes
Program terminates
Syntax error
Stop executing
15
What is a sentinel value?
Special operator
End of input signal
Loop counter
Type of loop
16
Purpose of break in a loop?
Exit loop immediately
Continue next iteration
Pause the loop
None of the above
17
Output of code: char c = 'A'; if (c < 'Z') { System.out.println("A is less than Z"); }
A is less than Z
Compilation error
None of the above
No output
18
Difference between while and do-while loop?
while runs at least once
do-while runs at least once
No difference
do-while executes before checking
19
What does the else statement do?
Declares a loop
If condition true
Defines a class
If condition false