WorksheetsLONG TEST in Computer Programming (Java NCIII)
Total questions: 45
Worksheet time: 25mins
Which keyword is used in Java to create a decision structure?
case
for
if
loop
What symbol is used in Java to represent "equal to" in a condition?
=
==
===
:=
Which of the following is a valid relational operator in Java?
&
%
+
<=
In a flowchart, which shape is used to represent a decision?
Diamond
Oval
Parallelogram
Rectangle
If x = 5 and the condition is if (x > 10), what will happen?
The program will crash
The if block will not execute
The compiler will show an error
The code inside the if bracket will execute
Which of the following best describes an if-else statement?
Terminates the program
Repeats a block of code multiple times
Executes only when the condition is false
Executes a block of code if true, another if false
In a flowchart, if the decision is true, what usually happens?
The program restarts
The flow is terminated
The flow goes to the "Yes" branch
The flowchart ends immediately
If the condition (score > 75) is used, what does it check?
If score is always 75
If score is less than 75
If score is greater than 75
If score is greater than or equal to 75
What is the output of the following code if x = 12?
if (x > 10) { System.out.println("Pass"); }
Error
Fail
No output
Pass
Which code correctly checks if a number n is negative?
if (n > 0)
if (n >= 0)
if (n < 0)
if (n <= 0)
A flowchart uses a decision labeled is x > 100?. If x = 50, where will the flow go?
Both branches
No branch
Program ends
Yes branch
Given the flowchart below: • Start → Input age → Decision (is age >= 18?) → Yes: "Adult" → End • No: "Minor" → End
What does it represent?
Even/Odd check
Looping structure
Positive/Negative check
Voting eligibility check
Which of the following code will is correct in showing the remarks "Passed" of an average grade?
I. if (ave >= 75)
II. if (ave < 75)
III. if (ave > 74)
IV. if (ave <= 74)
I, II
I, III
II, III
All of the above
What will happen if we forget to write else in an if-else structure?
The compiler will show an error
The program will crash
The program will loop forever
The program will only run the if part when true
Evaluate the condition: If age = 65, which expression is correct for checking Senior Citizen?
if (age >= 60)
if (age > 60)
if (age = 18)
if (age < 19)
Which code is most appropriate to check if BMI is less than 30?
if (BMI < 30)
if (BMI <= 30)
if (BMI == 30)
if (BMI >= 30)
Which of the following statements is true about the if statement in Java?
It allows conditional execution of code
It declares variables
It ends a program
It repeats a block of code continuously
In Java, which data type is commonly used in an if condition?
boolean
char
int
String
What shape is used to represent Start/End in a flowchart?
Diamond
Oval
Parallelogram
Rectangle
The condition if (age < 18) means:
The code executes only if age is 18
The code executes for all values of age
The code executes only if age is less than 18
The code executes only if age is greater than 18
Which of the following flowchart symbols is correctly matched?
Decision = Rectangle
Input = Oval
Output = Parallelogram
Process = Diamond
In Java, what happens if an if condition is false but no else is written?
The program crashes
The program ends
The program repeats
The program skips the if block
Which of the following will cause an infinite loop?
for (int counter = 0; counter < 1; counter++ )
for (int counter = 1; counter < 0; counter++ )
for (int counter = 0; counter < 1; counter-- )
for (int counter = 1; counter < 0; counter-- )
What will the flowchart do if the condition is false?
Execute No path
Execute Yes path
Restart the program
Stop immediately
Which code segment is correct for printing "Adult" if age >= 18, otherwise "Minor"?
if (age >= 18) System.out.println("Adult"); else System.out.println("Minor");
if (age > 18) System.out.println("Minor"); else System.out.println("Adult");
if (age = 18) System.out.println("Adult"); else System.out.println("Minor");
if (age > 18); System.out.println("Adult"); else System.out.println("Minor");
Which flowchart decision represents the Java code: if (y == 100)
is y < 100?
is y > 100?
is y = 100?
is y == 100?
Identify the error: if (x = 10) { System.out.println("Correct"); }
Nothing is wrong
System.out.println is incorrect
The curly braces are missing
The operator should be ==
Which flowchart corresponds to the following Java code? if (score >= 75) { System.out.println("Passed"); } else { System.out.println("Failed"); }
Decision : is score < 75? Yes → "Passed"
Decision : is score >= 75? Yes → "Passed", No → "Failed"
Process → End
Start → Output → End
Which of the following is a logic error in Java if conditions?
Forgetting curly braces
Missing semicolon
Using = instead of ==
Using == instead of =
If a program always executes the else part, what might be the problem?
The compiler skips the if statement
The condition is always false
The condition is always true
There is no condition
Which of the following represents the best practice in writing nested if statements?
Avoid using brackets for single statements
Use if-else-if ladder for clarity
Use multiple nested ifs always
Write all conditions separately
What symbol is used to call a method in Java?
Colon :
Curly braces {}
Parentheses ()
Square brackets []
What is the correct syntax to declare a method in Java?
public void methodName() { }
public static void methodName()
public static void methodName { }
public static void main(String[]args){ }
Why do we use methods in Java?
To compile faster
To reduce memory usage
To store data permanently
To reuse code and improve readability
What happens when a method is called?
The class reloads
The compiler restarts
The program terminates
Program control transfers to the method
What is the output of the following code?
Public class Greetings{
public static void greet() {
System.out.println("Hello!");
}
}
Hello!
greet
None
Syntax error
How do you call the method mentioned in the code?
Public class Greetings{
public static void greet() {
System.out.println("Hello!");
}
}
Greetings;
Greetings();
call Greetings();
Greetings("Hello!");
For numbers 38-39
What will happen to the program if you use ++ in the update?
for (int counter = 2; counter > 5; counter ___) { }
Loops 2 times
Loops 3 times
Infinite Loop
The loop terminates
What will happen to the program if you use == 10 in the Test Expression?
for (int counter = 5; counter ___ ; counter++ { }
Loops 5 times
Loops 10 times
Infinite Loop
The loop terminates
Which is the best approach to avoid infinite loops?
Ensure loop condition will eventually become false
Use nested loops carefully
Do not use do while
Avoid using >=
Which of the following executes at least once even if the condition is false?
do-while
for
nested loop
while
What is printed by this code?
for(int i=1; i<=3; i++) {
for(int j=1; j<=2; j++) {
System.out.print(i + "" + j + " ");
}
}
11 12 21 22 31 32
11 21 12 22 13 23
12 22 32
13 23 33
How many stars will this nested loop print? for (int star = 3; star > 1; star--){ System.out.print("*"); }
1
2
3
4
Which loop structure is more readable for beginners?
Do While
For
Nested Loop
While
