wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Topic 4.2, 4.3, 4.4, 4.5

Total questions: 66

Worksheet time: 2hrs 12mins

Name
Class
Date
1.
Syntax errors are always spotted when the program is compiled or interpreted.
a)
True
b)
False
2.
A program won't run if there is a logic error.
a)
False
b)
True
3.
Which statement best describes logic errors?
a)
An error in a program that causes it to produce incorrect ouputs but not a crash.
b)
An error in a program that causes it to crash.
c)
An error in the program caused by mis-spelt instructions.
d)
An error in a program caused by hardware failure.
4.
Which of these expressions will generate a logic error when the expected output is 10?
a)
answer = 2 + 3 * 2
b)
answer = (2 + 3) * 2
c)
answer = 2 + 3 x 2
d)
answer = {2 + 3} * 2
5.
Which statement contains a syntax error
a)
print("Hello")
b)
PRINT("Hello")
c)
print("hello")
d)
print("HELLO")
6.

Which of the following is an example of a logic error?

a)

Misspelling a keyword in the code.

b)

Forgetting to close a bracket.

c)

Using the wrong formula to calculate the area of a circle.

d)

Missing a semicolon at the end of a statement.

7.

Which of the following is most likely to cause a syntax error?

a)

Using a variable before declaring it.

b)

Dividing a number by zero.

c)

Forgetting to include a library or module.

d)

Using a single equal sign instead of a double equal sign for comparison.

8.

Which of the following best describes a runtime error?

a)

An error that occurs when the program is being compiled.

b)

An error that occurs when the program is running, often due to invalid operations.

c)

An error that occurs due to incorrect logic in the code.

d)

An error that occurs when the code does not follow the syntax rules.

9.

Which of the following is a common symptom of a runtime error?

a)

The program fails to compile.

b)

The program produces incorrect results without crashing.

c)

The program crashes or terminates unexpectedly during execution.

d)

The program runs slower than expected.

10.

What can dividing by zero cause in a program

a)

Syntax Error

b)

logic error

c)

Runtime error

11.

Observe the above statement to identify the type of error occurred.

a)

Logic error

b)

Syntax error

c)

Run–time error

d)

Operator error

12.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

13.

What would the new value of A be?

A=1;

A--;

a)

0

b)

1

c)

2

d)

-1

14.

What's the value of below?


int i=5;


System.out.println(i);

System.out.println(++i);

a)

6

7

b)

67

c)

7

8

d)

5

6

15.

What does the following code output?

int x = 1;

System.out.println(x++);

a)

1

b)

2

c)

compilation error

d)

runtime error

16.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

17.

What symbol represents the and operator in Java?

a)

AND

b)

and

c)

&

d)

&&

18.

What symbol represents the or operator in Java?

a)

OR

b)

or

c)

||

d)

|

19.
Which one of the following is NOT a logical operator?
a)
||
b)
&&
c)
$$
d)
!
20.

If a=2, b=5, c=3

Find result for : 8 * (a + b + c) – a % c

a)

80

b)

81

c)

77

d)

78

21.

int a = 2, b = 2, c = 0;

double d = 30.1;


Find answer for = (a > b) &&(( c <d) || (c!=a))

a)

35.9

b)

80

c)

true

d)

false

22.

Java code to create a non-element array of student marks with the size of 20.

a)

double mark;

b)

double [20] mark = new double;

c)

double [ ] mark = new mark [20];

d)

double [ ] mark = new double [20];

23.

Java code to create a non-element array of student name with size 15.

a)

String [ ] name = new String;

b)

String [ ] name = new String [15];

c)

name = new String [15];

d)

String [15] name = new String [ ];

24.

Java code to create an array of student id with element 115331, 450055, 555641, 875560 and 987555.

a)

int [ ] id = new {115331, 450055, 555641, 875560, 987555};

b)

int [5] id = {115331, 450055, 555641, 875560, 987555};

c)

int [ ] id = {115331, 450055, 555641, 875560, 987555};

d)

int [ ] id = new int [5];

25.

Java code to create an array of subject code with element S, M, C, P, I and K.

a)

char [ ] code = {'S', 'M', 'C', 'P', 'I' and 'K'};

b)

char [ ] code = {S, M, C, P, I, K};

c)

char [ ] code = {"S", "M", "C", "P", "I", "K"};

d)

char [ ] code = {'S', 'M', 'C', 'P', 'I', 'K'};

26.

Java code to display the size of an array name studentname[ ].

a)

System.out.println("The size is " + studentname[ index ]);

b)

System.out.println("The size is " + studentname.length);

c)

System.out.println("The size is " + length.length);

d)

System.out.println("The size is " + studentname);

27.

Java code to display all elements of array studentname[ ].

a)
b)
c)
d)
28.

Java code to read elements into array studentname[ ].

a)
b)
c)
d)
29.

Java code to read elements into array customerid[ ].

a)
b)
c)
d)

None of the above is the right answer.

30.

Based on the code segment below:- identify the name of the array.


for(int j=0; j<balance.length; j++)

{

System.out.print("Enter amount: ");

.......

}

a)

No answer.

b)

temp[ ]

c)

balance

d)

balance [ i ]

31.

Choose the correct syntax for Array.

a)

b)

c)

32.

The first element in Array is

a)

int i [0]

b)

int i [1]

33.

The second element in Array is

a)

int i [1]

b)

int i[2]

34.

Which one is an Array

a)

int Shape

b)

int Shape[ ]

35.

Given array

int myPins [ ] = {2, 4, 8, 3, 6};

The last element is:

a)

2

b)

6

36.

Given array

int myPins [ ] = {2, 4, 8, 3, 6};

a)

myPins[1] = 2

b)

myPins[0] = 2

37.

int myArray [ ] = {8, 9, 11};

which one is invalid?

a)

myArray [0]

b)

myArray [3]

38.

What are the legal indexes for the array ar, given the following declaration:

int [ ] ar = {2, 4, 6, 8 } ;

a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
39.

For the array:

int stats[3];

What is the range of the index?

a)

0 to 3

b)

0 to 2

c)

1 to 3

d)

0 to 4

40.

int [] nums = {2, 3, 5, 8, 9, 11};

How would you access the fourth element in nums?

a)

nums[4]

b)

nums[3]

c)

nums(4)

d)

nums(3)

41.
The first value of an array called quizzes can be accessed with which of the following statements?
a)
quizzes[1] = 100;
b)
quizzes[0] = 100;
c)
quizzes[zero] = 100;
d)
quizzes[one] = 100;
42.
Which of the following statements outputs the fifth value in the quizzes array?
a)
System.out.println(quizzes[5]);
b)
quizzes[4];
c)
quizzes[5];
d)
System.out.println(quizzes[4]);
43.
Index values of an array range from ______________.
a)
0 to length – 1
b)
1 to length
c)
0 to length
d)
0 to length + 1
44.
Create an array of 12 strings called months.
a)
String[] months = new String[12];
b)
String months = new String[12];
c)
String[] months = new String[];
d)
String[12] months = new String[];
45.

What value is at index 1 in this array?

String[] names = {"Mack", "Dennis", "Dee", "Charlie"};

a)

Mack

b)

Dennis

c)

Dee

d)

Charlie

46.

What is the correct way to create an array with these three numbers: 12 8 15

a)

int[] = {12, 8, 15};

b)

int[] nums = {12 8 15};

c)

int[] nums = new {12, 8, 15};

d)

int[] nums = {12, 8, 15};

47.
What is returned by values[5]?
a)
9
b)
12
c)
6
d)
8
48.
for(int i=0; i<10; i++)
           numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
a)
1
b)
2
c)
3
d)
4
49.

What does the following segment of code print out?

int[] numArray = { 2, 7, 4, 12, 0, 2 };

System.out.println("Number: " + numArray[2]);

a)

Number: 2

b)

Number: 7

c)

Number: 4

d)

Number: 12

50.

What is the correct way to assign 4 to the 3rd position of the nums1 array?

a)

b)

c)

d)

51.

What is the index of the 12 in this array?

(a)  

52.

What is the length of the following array: int[ ] data = { 12, 34, 9, 0, -62, 88 };

a)

5

b)

6

c)

88

d)

8

53.

Which statement about identifiers is correct?

a)

Identifiers are not case sensitive.

b)

Spaces are permitted inside identifiers.

c)

Identifiers can be made up of letters, digits, and the underscore (_) character and $ sign.

d)

Identifiers can use symbols such as ? or %.

54.

int, void, public, static, are reserved words.

a)

true

b)

false

55.

It is used to store two types of values, i.e., true or false. This data type is commonly used as a flag in code logic.

a)

boolean

b)

byte

c)

char

d)

String

56.

What symbol represents the and operator in Java?

a)

AND

b)

and

c)

&

d)

&&

57.

What symbol represents the or operator in Java?

a)

OR

b)

or

c)

||

d)

|

58.
Which one of the following is NOT a logical operator?
a)
||
b)
&&
c)
$$
d)
!
59.

If a=2, b=5, c=3

Find result for : 8 * (a + b + c) – a % c

a)

80

b)

81

c)

77

d)

78

60.

int a = 2, b = 2, c = 0;

double d = 30.1;

Find answer for = (a > b) &&(( c <d) || (c!=a))

a)

35.9

b)

80

c)

true

d)

false

61.

Which of the following statement is valid

a)

int a+b=5;

b)

double char =m;

c)

int name;

name = 5;

d)

IQ = 5;

int IQ;

62.

Which of these cannot be used for a variable name in java ?

a)

Identifier & keyword

b)

Identifier

c)

Keyword

d)

None of the mentioned

63.

Which one is arithmetic expression?

a)

3 == 5

b)

b * c - d

c)

!(a > b)

64.

ax2 + bcx +d\frac{ax^2\ +\ b}{cx\ +d}

Based on algebraic expression above, tick the correct Java expression.

a)

(a * x * x + b) / ((c * x + d)

b)

(a * Math.pow(x,2) + b) / (c * x + d)

c)

((a)(x)(x) + (b)) / ((c)(x) + d)

d)

(b + x *(x * (a))) / (d + x * (c))

65.

Declare a constant for PI with value 3.142

(a)  

66.

Create a variable called myNum of type int and assign it the value 15

(a)