Page 494 - CA_Blue( J )_Class10
P. 494
v. How many times will the following loop execute? Write the output of the code: [2]
intx=10;
while(true){
System.out.println(x++*2);
if(x%3==0)
break;
} [Analysis]
Ans. Loop is executed two times
20
22
vi. Write the output of the following String methods: [2]
String x= "Galaxy ", y= "Games ";
(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y)); [Analysis]
Ans. (a) true
(b) –1
vii. Predict the output of the following code snippet: [2]
char ch='B';
char chr= Character.toLowerCase(ch);
int n=(int) chr-10;
System.out.println((char)n+"\t"+chr); [2]
Ans. x b
viii. A student is trying to convert the string present in x to a numerical value, so that he can find the square root of the
converted value, However the code has an error. Name the error (syntax/logical/runtime). Correct the code so that it
compiles and runs correctly. [2]
String x="25";
int y=Double.parseDouble(x);
double r=Math.sqrt(y);
System.out.println(r); [Analysis]
Ans. Syntax error, double y = Double.parseDouble(x)
ix. Consider the following program segment and answer the questions below: [2]
class calculate
{
int a; double b;
calculate()
{
a=0;
b=0.0;
}
calculate(int x, double y)
{
a=x;
b=y;
}
void sum()
{
System.out.println(a*b);
}} [Analysis]
Name the type of constructors used in the above program segment.
Ans. Default constructor, Parameterized Constructor
x. Consider the following program segment and answer the questions given below: [2]
int x[ ] [ ] = { {2,4,5,6}. {5,7,8,1}, {34, 1,10, 9}};
a. What is the position of 34?
b. What is the result of x[2][3] + x[1][2]? [Analysis]
Ans. (a) x[2][0]
(b) 17 (9+8)
492492 Touchpad Computer Applications-X

