Final Exam Answer1
Final Exam Answer1
II) How can (10.99) be stored into int variable x using cast?
int x =__________;
V) Array types look like other Java types except they are followed by
A. ( ) B. [ ] C. { } D. //
VII) Translating a program in a high-level language into a low-level language, all at once, in
preparation for later execution is called ……………..
IX) ……………. does NOT terminate the loop, it just skips some part of the loop.
XII) The --------- statement will immediately end the program as soon as it is invoked
XIII) The ----------- statements are necessary because without them, statements
in switch blocks fall through.
XV) Statements are at least executed once even if the condition is false in __________ loop
SECTION – B (5 x 3 = 15 MARKS)
Answer any FIVE Questions. Each Question carries THREE Marks.
The debugging is the process of tracking the errors down and correcting them. (1 mark)
— kinds of errors:
syntax – run time – logic (2 marks)
System.out.println(numbers[i]);
}}}
class Exercise { 1
public static void main(String[] args) {
2
3
int counter = 1; 4 (2.5 marks)
do { 5
System.out.println(counter);
if (counter %7 == 0) {
6
System.out.println("Multiple of 7 encountered. Quitting loop!"); 7
break;
} Multiple of 7 encountered.
counter++; } Quitting loop! (0.5 mark)
while (counter <= 10);
}}
1. Break (1 mark)
2. Continue (1 mark)
3. Return (1 mark)
9. Rewrite the following program by using do-while loop to print the even numbers
from (1 – 10):
public static void main( public static void main(String[ ] args) { (0.5 mark)
int i = 1; (0.5 mark)
String[] args) { do { (1mark)
if(i%2 == 0) (0.5 mark)
for(int i = 1; i<=10; i++) {
System.out.print(i + " "); (0.5 mark)
if(i%2 == 0)
i++; (0.5 mark)
System.out.print(i + " "); }
} while(i <= 10); (1mark)
System.out.println(); } }
}}