(a) Evaluate the value of n if value of p = 5, q = 19

ICSE Class 10 Computer Applications PYQ · 2015 Paper · Section A

21 Mark · 2015 · Section A · 2015 Paper

(a) Evaluate the value of n if value of p = 5, q = 19

int n = (q – p) > (p – q) ? (q – p) : (p – q);

Show SolutionHide Solution↓

    int n = (q – p) > (p – q) ? (q – p) : (p – q)
⇒ int n = (19 - 5) > (5 - 19) ? (19 - 5) : (5 - 19)
⇒ int n = 14 > -14 ? 14 : -14
⇒ int n = 14 [∵ 14 > -14 is true so ? : returns 14]

Final value of n is 14

(b) Arrange the following primitive data types in an ascending order of their size:

(i) char (ii) byte (iii) double (iv) int

byte, char, int, double

(c) What is the value stored in variable res given below:

double res = Math.pow ("345".indexOf('5'), 3);

Value of res is 8.0
Index of '5' in "345" is 2. Math.pow(2, 3) means 23 which is equal to 8

(d) Name the two types of constructors

Parameterized constructors and Non-Parameterized constructors.

(e) What are the values of a and b after the following function is executed, if the values passed are 30 and 50:

void paws(int a, int b)
{
    a=a+b;
    b=a–b;
    a=a–b;
    System.out.println(a+ "," +b);
}

Value of a is 50 and b is 30.
Output of the code is:

50,30
← Previous questionNext question →

Browse the free Computer Applications sample bank