WorksheetsTopic 4.2, 4.3, 4.4, 4.5
Total questions: 66
Worksheet time: 2hrs 12mins
Which of the following is an example of a logic error?
Misspelling a keyword in the code.
Forgetting to close a bracket.
Using the wrong formula to calculate the area of a circle.
Missing a semicolon at the end of a statement.
Which of the following is most likely to cause a syntax error?
Using a variable before declaring it.
Dividing a number by zero.
Forgetting to include a library or module.
Using a single equal sign instead of a double equal sign for comparison.
Which of the following best describes a runtime error?
An error that occurs when the program is being compiled.
An error that occurs when the program is running, often due to invalid operations.
An error that occurs due to incorrect logic in the code.
An error that occurs when the code does not follow the syntax rules.
Which of the following is a common symptom of a runtime error?
The program fails to compile.
The program produces incorrect results without crashing.
The program crashes or terminates unexpectedly during execution.
The program runs slower than expected.
What can dividing by zero cause in a program
Syntax Error
logic error
Runtime error
Observe the above statement to identify the type of error occurred.
Logic error
Syntax error
Run–time error
Operator error
What would the new value of A be?
A=1;
a++;
1
2
3
4
What would the new value of A be?
A=1;
A--;
0
1
2
-1
What's the value of below?
int i=5;
System.out.println(i);
System.out.println(++i);
6
7
67
7
8
5
6
What does the following code output?
int x = 1;
System.out.println(x++);
1
2
compilation error
runtime error
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
What symbol represents the and operator in Java?
AND
and
&
&&
What symbol represents the or operator in Java?
OR
or
||
|
If a=2, b=5, c=3
Find result for : 8 * (a + b + c) – a % c
80
81
77
78
int a = 2, b = 2, c = 0;
double d = 30.1;
Find answer for = (a > b) &&(( c <d) || (c!=a))
35.9
80
true
false
Java code to create a non-element array of student marks with the size of 20.
double mark;
double [20] mark = new double;
double [ ] mark = new mark [20];
double [ ] mark = new double [20];
Java code to create a non-element array of student name with size 15.
String [ ] name = new String;
String [ ] name = new String [15];
name = new String [15];
String [15] name = new String [ ];
Java code to create an array of student id with element 115331, 450055, 555641, 875560 and 987555.
int [ ] id = new {115331, 450055, 555641, 875560, 987555};
int [5] id = {115331, 450055, 555641, 875560, 987555};
int [ ] id = {115331, 450055, 555641, 875560, 987555};
int [ ] id = new int [5];
Java code to create an array of subject code with element S, M, C, P, I and K.
char [ ] code = {'S', 'M', 'C', 'P', 'I' and 'K'};
char [ ] code = {S, M, C, P, I, K};
char [ ] code = {"S", "M", "C", "P", "I", "K"};
char [ ] code = {'S', 'M', 'C', 'P', 'I', 'K'};
Java code to display the size of an array name studentname[ ].
System.out.println("The size is " + studentname[ index ]);
System.out.println("The size is " + studentname.length);
System.out.println("The size is " + length.length);
System.out.println("The size is " + studentname);
Java code to display all elements of array studentname[ ].
Java code to read elements into array studentname[ ].
Java code to read elements into array customerid[ ].
None of the above is the right answer.
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: ");
.......
}
No answer.
temp[ ]
balance
balance [ i ]
Choose the correct syntax for Array.
The first element in Array is
int i [0]
int i [1]
The second element in Array is
int i [1]
int i[2]
Which one is an Array
int Shape
int Shape[ ]
Given array
int myPins [ ] = {2, 4, 8, 3, 6};
The last element is:
2
6
Given array
int myPins [ ] = {2, 4, 8, 3, 6};
myPins[1] = 2
myPins[0] = 2
int myArray [ ] = {8, 9, 11};
which one is invalid?
myArray [0]
myArray [3]
What are the legal indexes for the array ar, given the following declaration:
int [ ] ar = {2, 4, 6, 8 } ;
0, 1, 2, 31, 2, 3, 40, 2, 4, 6For the array:
int stats[3];
What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
int [] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums?
nums[4]
nums[3]
nums(4)
nums(3)
What value is at index 1 in this array?
String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
Mack
Dennis
Dee
Charlie
What is the correct way to create an array with these three numbers: 12 8 15
int[] = {12, 8, 15};
int[] nums = {12 8 15};
int[] nums = new {12, 8, 15};
int[] nums = {12, 8, 15};
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 5?
What does the following segment of code print out?
int[] numArray = { 2, 7, 4, 12, 0, 2 };
System.out.println("Number: " + numArray[2]);
Number: 2
Number: 7
Number: 4
Number: 12
What is the correct way to assign 4 to the 3rd position of the nums1 array?
What is the index of the 12 in this array?
(a)
What is the length of the following array: int[ ] data = { 12, 34, 9, 0, -62, 88 };
5
6
88
8
Which statement about identifiers is correct?
Identifiers are not case sensitive.
Spaces are permitted inside identifiers.
Identifiers can be made up of letters, digits, and the underscore (_) character and $ sign.
Identifiers can use symbols such as ? or %.
int, void, public, static, are reserved words.
true
false
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.
boolean
byte
char
String
What symbol represents the and operator in Java?
AND
and
&
&&
What symbol represents the or operator in Java?
OR
or
||
|
If a=2, b=5, c=3
Find result for : 8 * (a + b + c) – a % c
80
81
77
78
int a = 2, b = 2, c = 0;
double d = 30.1;
Find answer for = (a > b) &&(( c <d) || (c!=a))
35.9
80
true
false
Which of the following statement is valid
int a+b=5;
double char =m;
int name;
name = 5;
IQ = 5;
int IQ;
Which of these cannot be used for a variable name in java ?
Identifier & keyword
Identifier
Keyword
None of the mentioned
Which one is arithmetic expression?
3 == 5
b * c - d
!(a > b)
cx +dax2 + b
Based on algebraic expression above, tick the correct Java expression.
(a * x * x + b) / ((c * x + d)
(a * Math.pow(x,2) + b) / (c * x + d)
((a)(x)(x) + (b)) / ((c)(x) + d)
(b + x *(x * (a))) / (d + x * (c))
Declare a constant for PI with value 3.142
(a)
Create a variable called myNum of type int and assign it the value 15
(a)
