wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

LONG TEST in Computer Programming (Java NCIII)

Total questions: 45

Worksheet time: 25mins

Name
Class
Date
1.

Which keyword is used in Java to create a decision structure?

a)

case

b)

for

c)

if

d)

loop

2.

What symbol is used in Java to represent "equal to" in a condition?

a)

=

b)

==

c)

===

d)

:=

3.

Which of the following is a valid relational operator in Java?

a)

&

b)

%

c)

+

d)

<=

4.

In a flowchart, which shape is used to represent a decision?

a)

Diamond

b)

Oval

c)

Parallelogram

d)

Rectangle

5.

If x = 5 and the condition is if (x > 10), what will happen?

a)

The program will crash

b)

The if block will not execute

c)

The compiler will show an error

d)

The code inside the if bracket will execute

6.

Which of the following best describes an if-else statement?

a)

Terminates the program

b)

Repeats a block of code multiple times

c)

Executes only when the condition is false

d)

Executes a block of code if true, another if false

7.

In a flowchart, if the decision is true, what usually happens?

a)

The program restarts

b)

The flow is terminated

c)

The flow goes to the "Yes" branch

d)

The flowchart ends immediately

8.

If the condition (score > 75) is used, what does it check?

a)

If score is always 75

b)

If score is less than 75

c)

If score is greater than 75

d)

If score is greater than or equal to 75

9.

What is the output of the following code if x = 12?

if (x > 10) { System.out.println("Pass"); }

a)

Error

b)

Fail

c)

No output

d)

Pass

10.

Which code correctly checks if a number n is negative?

a)

if (n > 0)

b)

if (n >= 0)

c)

if (n < 0)

d)

if (n <= 0)

11.

A flowchart uses a decision labeled is x > 100?. If x = 50, where will the flow go?

a)

Both branches

b)

No branch

c)

Program ends

d)

Yes branch

12.

Given the flowchart below: • Start → Input age → Decision (is age >= 18?) → Yes: "Adult" → End • No: "Minor" → End

What does it represent?

a)

Even/Odd check

b)

Looping structure

c)

Positive/Negative check

d)

Voting eligibility check

13.

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)

a)

I, II

b)

I, III

c)

II, III

d)

All of the above

14.

What will happen if we forget to write else in an if-else structure?

a)

The compiler will show an error

b)

The program will crash

c)

The program will loop forever

d)

The program will only run the if part when true

15.

Evaluate the condition: If age = 65, which expression is correct for checking Senior Citizen?

a)

if (age >= 60)

b)

if (age > 60)

c)

if (age = 18)

d)

if (age < 19)

16.

Which code is most appropriate to check if BMI is less than 30?

a)

if (BMI < 30)

b)

if (BMI <= 30)

c)

if (BMI == 30)

d)

if (BMI >= 30)

17.

Which of the following statements is true about the if statement in Java?

a)

It allows conditional execution of code

b)

It declares variables

c)

It ends a program

d)

It repeats a block of code continuously

18.

In Java, which data type is commonly used in an if condition?

a)

boolean

b)

char

c)

int

d)

String

19.

What shape is used to represent Start/End in a flowchart?

a)

Diamond

b)

Oval

c)

Parallelogram

d)

Rectangle

20.

The condition if (age < 18) means:

a)

The code executes only if age is 18

b)

The code executes for all values of age

c)

The code executes only if age is less than 18

d)

The code executes only if age is greater than 18

21.

Which of the following flowchart symbols is correctly matched?

a)

Decision = Rectangle

b)

Input = Oval

c)

Output = Parallelogram

d)

Process = Diamond

22.

In Java, what happens if an if condition is false but no else is written?

a)

The program crashes

b)

The program ends

c)

The program repeats

d)

The program skips the if block

23.

Which of the following will cause an infinite loop?

a)

for (int counter = 0; counter < 1; counter++ )

b)

for (int counter = 1; counter < 0; counter++ )

c)

for (int counter = 0; counter < 1; counter-- )

d)

for (int counter = 1; counter < 0; counter-- )

24.

What will the flowchart do if the condition is false?

a)

Execute No path

b)

Execute Yes path

c)

Restart the program

d)

Stop immediately

25.

Which code segment is correct for printing "Adult" if age >= 18, otherwise "Minor"?

a)

if (age >= 18) System.out.println("Adult"); else System.out.println("Minor");

b)

if (age > 18) System.out.println("Minor"); else System.out.println("Adult");

c)

if (age = 18) System.out.println("Adult"); else System.out.println("Minor");

d)

if (age > 18); System.out.println("Adult"); else System.out.println("Minor");

26.

Which flowchart decision represents the Java code: if (y == 100)

a)

is y < 100?

b)

is y > 100?

c)

is y = 100?

d)

is y == 100?

27.

Identify the error: if (x = 10) { System.out.println("Correct"); }

a)

Nothing is wrong

b)

System.out.println is incorrect

c)

The curly braces are missing

d)

The operator should be ==

28.

Which flowchart corresponds to the following Java code? if (score >= 75) { System.out.println("Passed"); } else { System.out.println("Failed"); }

a)

Decision : is score < 75? Yes → "Passed"

b)

Decision : is score >= 75? Yes → "Passed", No → "Failed"

c)

Process → End

d)

Start → Output → End

29.

Which of the following is a logic error in Java if conditions?

a)

Forgetting curly braces

b)

Missing semicolon

c)

Using = instead of ==

d)

Using == instead of =

30.

If a program always executes the else part, what might be the problem?

a)

The compiler skips the if statement

b)

The condition is always false

c)

The condition is always true

d)

There is no condition

31.

Which of the following represents the best practice in writing nested if statements?

a)

Avoid using brackets for single statements

b)

Use if-else-if ladder for clarity

c)

Use multiple nested ifs always

d)

Write all conditions separately

32.

What symbol is used to call a method in Java?

a)

Colon :

b)

Curly braces {}

c)

Parentheses ()

d)

Square brackets []

33.

What is the correct syntax to declare a method in Java?

a)

public void methodName() { }

b)

public static void methodName()

c)

public static void methodName { }

d)

public static void main(String[]args){ }

34.

Why do we use methods in Java?

a)

To compile faster

b)

To reduce memory usage

c)

To store data permanently

d)

To reuse code and improve readability

35.

What happens when a method is called?

a)

The class reloads

b)

The compiler restarts

c)

The program terminates

d)

Program control transfers to the method

36.

What is the output of the following code?

Public class Greetings{

public static void greet() {

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

}

}

a)

Hello!

b)

greet

c)

None

d)

Syntax error

37.

How do you call the method mentioned in the code?

Public class Greetings{

public static void greet() {

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

}

}

a)

Greetings;

b)

Greetings();

c)

call Greetings();

d)

Greetings("Hello!");

38.

For numbers 38-39

4 lines
39.

What will happen to the program if you use ++ in the update?

for (int counter = 2; counter > 5; counter ___) { }

a)

Loops 2 times

b)

Loops 3 times

c)

Infinite Loop

d)

The loop terminates

40.

What will happen to the program if you use == 10 in the Test Expression?

for (int counter = 5; counter ___ ; counter++ { }

a)

Loops 5 times

b)

Loops 10 times

c)

Infinite Loop

d)

The loop terminates

41.

Which is the best approach to avoid infinite loops?

a)

Ensure loop condition will eventually become false

b)

Use nested loops carefully

c)

Do not use do while

d)

Avoid using >=

42.

Which of the following executes at least once even if the condition is false?

a)

do-while

b)

for

c)

nested loop

d)

while

43.

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 + " ");

}

}

a)

11 12 21 22 31 32

b)

11 21 12 22 13 23

c)

12 22 32

d)

13 23 33

44.

How many stars will this nested loop print? for (int star = 3; star > 1; star--){ System.out.print("*"); }

a)

1

b)

2

c)

3

d)

4

45.

Which loop structure is more readable for beginners?

a)

Do While

b)

For

c)

Nested Loop

d)

While