(a) Name the following:
- (a)A keyword used to call a package in the program.
- (b)Any one reference data type.
Show SolutionHide Solution↓
- import
- Array
(b) What are the two ways of invoking functions?
Call by value and call by reference.
(c) State the data type and value of res after the following is executed:
char ch='t'; res= Character.toUpperCase(ch);
Data type of res is char and its value is T.
(d) Give the output of the following program segment and also mention the number of times the loop is executed:
int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a%b == 0)
break;
}
System.out.println(a);
Output of the above code is 12 and loop executes 2 times.
This dry run explains the working of the loop.
| a | b | Remarks |
|---|---|---|
| 6 | 4 | 1st Iteration |
| 12 | 4 | 2nd Iteration |
In 2nd iteration, as a%b becomes 0 so break statement is executed and the loop exits. Program control comes to the println statement which prints the output as current value of a which is 12.
(e) Write the output:
char ch = 'F'; int m = ch; m=m+5; System.out.println(m + " " + ch);
Output of the above code is:
75 F
The statement int m = ch; assigns the ASCII value of F (which is 70) to variable m. Adding 5 to m makes it 75. In the println statement, the current value of m which is 75 is printed followed by space and then value of ch which is F.