ICSE Class 10 Computer Applications Question 1 of 6

Solved 2014 Question Paper ICSE Class 10 Computer Applications — Question 3

Back to all questions
3
Question

Question 3

(a) List the variables from those given below that are composite data types:

  1. static int x;
  2. arr[i]=10;
  3. obj.display();
  4. boolean b;
  5. private char chr;
  6. String str;

Answer

The composite data types are:

  • arr[i]=10;
  • obj.display();
  • String str;

(b) State the output of the following program segment:

String str1 = "great"; String str2 = "minds";
System.out.println(str1.substring(0,2).concat(str2.substring(1)));
System.out.println(("WH" + (str1.substring(2).toUpperCase())));

Answer

The output of the above code is:

grinds
WHEAT

Explanation:

  1. str1.substring(0,2) returns "gr". str2.substring(1) returns "inds". Due to concat both are joined together to give the output as "grinds".
  2. str1.substring(2) returns "eat". It is converted to uppercase and joined to "WH" to give the output as "WHEAT".

(c) What are the final values stored in variable x and y below?

double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b)); 

Answer

The final value stored in variable x is 6.0 and y is 15.0.

Explanation:

  1. Math.ceil(a) gives -6.0 and Math.abs(-6.0) is 6.0.
  2. Math.max(a,b) gives 14.74 and Math.rint(14.74) gives 15.0.

(d) Rewrite the following program segment using if-else statements instead of the ternary operator:

String grade = (marks>=90)?"A": (marks>=80)? "B": "C";

Answer
String grade;
if (marks >= 90)
    grade = "A";
else if (marks >= 80)
    grade = "B";
else
    grade = "C";

(e) Give the output of the following method:

public static void main (String [] args){
int a = 5;
a++;
System.out.println(a);
a -= (a--) - (--a);
System.out.println(a);} 

Answer

Output
6
4
Explanation
  1. a++ increments value of a by 1 so a becomes 6.
  2. a -= (a--) - (--a)
    ⇒ a = a - ((a--) - (--a))
    ⇒ a = 6 - (6 - 4)
    ⇒ a = 6 - 2
    ⇒ a = 4

(f) What is the data type returned by the library functions :

  1. compareTo()
  2. equals()

Answer

  1. int
  2. boolean

(g) State the value of characteristic and mantissa when the following code is executed:

String s = "4.3756";
int n = s.indexOf('.');
int characteristic=Integer.parseInt(s.substring(0,n));
int mantissa=Integer.valueOf(s.substring(n+1));

Answer

The value of characteristic is 4 and mantissa is 3756.

Index of . in String s is 1 so variable n is initialized to 1. s.substring(0,n) gives 4. Integer.parseInt() converts string "4" into integer 4 and this 4 is assigned to the variable characteristic.

s.substring(n+1) gives 3756 i.e. the string starting at index 2 till the end of s. Integer.valueOf() converts string "3756" into integer 3756 and this value is assigned to the variable mantissa.

(h) Study the method and answer the given questions.

public void sampleMethod()
{   for (int i=0; i < 3; i++)
    {   for (int j = 0; j<2; j++)
        {int number = (int)(Math.random() * 10);
        System.out.println(number); }}}
  1. How many times does the loop execute?
  2. What is the range of possible values stored in the variable number?

Answer

  1. The loops execute 6 times.
  2. The range is from 0 to 9.

(i) Consider the following class:

public class myClass {
public static int x=3, y=4;
public int a=2, b=3;}
  1. Name the variables for which each object of the class will have its own distinct copy.
  2. Name the variables that are common to all objects of the class.

Answer

  1. a, b
  2. x, y

(j) What will be the output when the following code segments are executed?

(i)

String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x="+x);
System.out.println("y="+y);

(ii)

System.out.println("The king said \"Begin at the beginning!\" to me.");

Answer

(i) The output of the code is:

x=1001
y=1001.0

(ii) The output of the code is:

The king said "Begin at the beginning!" to me.