KnowledgeBoat Logo

2019

Solved 2019 Question Paper ICSE Class 10 Computer Applications

Class 10 - ICSE Computer Applications Solved Question Papers


Section A

Question 1

(a) Name any two basic principles of Object-oriented Programming.

Answer

  1. Encapsulation
  2. Inheritance

(b) Write a difference between unary and binary operator.

Answer

unary operators operate on a single operand whereas binary operators operate on two operands.

(c) Name the keyword which:

  1. indicates that a method has no return type.
  2. makes the variable as a class variable

Answer

  1. void
  2. static

(d) Write the memory capacity (storage size) of short and float data type in bytes.

Answer

  1. short — 2 bytes
  2. float — 4 bytes

(e) Identify and name the following tokens:

  1. public
  2. 'a'
  3. ==
  4. { }

Answer

  1. Keyword
  2. Literal
  3. Operator
  4. Separator

Question 2

(a) Differentiate between if else if and switch-case statements

Answer

if else ifswitch-case
if else if can test for any Boolean expression like less than, greater than, equal to, not equal to, etc.switch-case can only test if the expression is equal to any of its case constants.
if else if can use different expression involving unrelated variables in its different condition expressions.switch-case statement tests the same expression against a set of constant values.

(b) Give the output of the following code:

String P = "20", Q ="19";
int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);

Answer

Output of the above code is:

2019
Explanation

Both Integer.parseInt() and Integer.valueOf() methods convert a string into integer. Integer.parseInt() returns an int value that gets assigned to a. Integer.valueOf() returns an Integer object (i.e. the wrapper class of int). Due to auto-boxing, Integer object is converted to int and gets assigned to b. So a becomes 20 and b becomes 19. 2019 is printed as the output.

(c) What are the various types of errors in Java?

Answer

There are 3 types of errors in Java:

  1. Syntax Error
  2. Runtime Error
  3. Logical Error

(d) State the data type and value of res after the following is executed:

char ch = '9';
res= Character.isDigit(ch);

Answer

Data type of res is boolean as return type of method Character.isDigit() is boolean. Its value is true as '9' is a digit.

(e) What is the difference between the linear search and the binary search technique?

Answer

Linear searchBinary search
Linear search works on sorted and unsorted arrays.Binary search works on only sorted arrays.
In Linear search, each element of the array is checked against the target value until the element is found or end of the array is reached.In Binary search, array is successively divided into 2 halves and the target element is searched either in the first half or in the second half.
Linear Search is slower.Binary Search is faster.

Question 3

(a) Write a Java expression for the following:
       |x2 + 2xy|

Answer

Math.abs(x * x + 2 * x * y)

(b) Write the return data type of the following functions:

  1. startsWith()
  2. random()

Answer

  1. boolean
  2. double

(c) If the value of basic=1500, what will be the value of tax after the following statement is executed?

tax = basic > 1200 ? 200 :100;

Answer

Value of tax will be 200. As basic is 1500, the condition of ternary operator — basic > 1200 is true. 200 is returned as the result of ternary operator and it gets assigned to tax.

(d) Give the output of following code and mention how many times the loop will execute?

int i;
for( i=5; i>=1; i--)
{
    if(i%2 == 1)
        continue;
    System.out.print(i+" ");
}

Answer

Output of the above code is:

4 2

Loop executes 5 times. The below table shows the dry run of the loop:

iOutputRemark
51st Iteration — As i % 2 gives 1 so condition is true and continue statement is executed. Nothing is printed in this iteration.
442nd Iteration — i % 2 is 0 so condition is false. Print statement prints 4 (current value of i) in this iteration.
343rd Iteration — i % 2 is 1 so continue statement is executed and nothing is printed in this iteration.
24 24th Iteration — i % 2 is 0. Print statement prints 2 (current value of i) in this iteration.
14 25th Iteration — i % 2 is 1 so continue statement is executed and nothing is printed in this iteration.
04 2As condition of loop (i >= 1) becomes false so loops exits and 6th iteration does not happen.

(e) State a difference between call by value and call by reference.

Answer

In call by value, actual parameters are copied to formal parameters. Any changes to formal parameters are not reflected onto the actual parameters. In call by reference, formal parameters refer to actual parameters. The changes to formal parameters are reflected onto the actual parameters.

(f) Give the output of the following:
       Math.sqrt(Math.max(9,16))

Answer

The output is 4.0.
First Math.max(9,16) is evaluated. It returns 16, the greater of its arguments. Math.sqrt(Math.max(9,16)) becomes Math.sqrt(16). It returns the square root of 16 which is 4.0.

(g) Write the output for the following:

String s1 = "phoenix"; String s2 ="island";
System.out.println(s1.substring(0).concat(s2.substring(2)));
System.out.println(s2.toUpperCase());

Answer

The output of above code is:

phoenixland
ISLAND
Explanation

s1.substring(0) results in phoenix. s2.substring(2) results in land. concat method joins both of them resulting in phoenixland. s2.toUpperCase() converts island to uppercase.

(h) Evaluate the following expression if the value of x=2, y=3 and z=1.

  v=x + --z + y++ + y

Answer

    v = x + --z + y++ + y
⇒ v = 2 + 0 + 3 + 4
⇒ v = 9

(i) String x[] = {"Artificial intelligence", "IOT", "Machine learning", "Big data"};

Give the output of the following statements:

  1. System.out.println(x[3]);
  2. System.out.println(x.length);

Answer

  1. Big data
  2. 4

(j) What is meant by a package? Give an example.

Answer

A package is a named collection of Java classes that are grouped on the basis of their functionality. For example, java.util.

Section B

Question 4

Design a class name ShowRoom with the following description:

Instance variables / Data members:
String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount

Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on following criteria

CostDiscount (in percentage)
Less than or equal to ₹100005%
More than ₹10000 and less than or equal to ₹2000010%
More than ₹20000 and less than or equal to ₹3500015%
More than ₹3500020%

void display() — To display customer name, mobile number, amount to be paid after discount.

Write a main method to create an object of the class and call the above member methods.

Answer

import java.util.Scanner;

public class ShowRoom
{
    private String name;
    private long mobno;
    private double cost;
    private double dis;
    private double amount;

    public ShowRoom()
    {
        name = "";
        mobno = 0;
        cost = 0.0;
        dis = 0.0;
        amount = 0.0;
    }

    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter customer name: ");
        name = in.nextLine();
        System.out.print("Enter customer mobile no: ");
        mobno = in.nextLong();
        System.out.print("Enter cost: ");
        cost = in.nextDouble();
    }
    
    public void calculate() {
        int disPercent = 0;
        if (cost <= 10000)
            disPercent = 5;
        else if (cost <= 20000)
            disPercent = 10;
        else if (cost <= 35000)
            disPercent = 15;
        else
            disPercent = 20;
        
        dis = cost * disPercent / 100.0;
        amount = cost - dis;
    }
    
    public void display() {
        System.out.println("Customer Name: " + name);
        System.out.println("Mobile Number: " + mobno);
        System.out.println("Amout after discount: " + amount);
    }
    
    public static void main(String args[]) {
        ShowRoom obj = new ShowRoom();
        obj.input();
        obj.calculate();
        obj.display();
    }
}
Output
BlueJ output of ShowRoom.java

Question 5

Using the switch-case statement, write a menu driven program to do the following:

(a) To generate and print Letters from A to Z and their Unicode

LettersUnicode
A65
B66
..
..
..
Z90

(b) Display the following pattern using iteration (looping) statement:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Answer

import java.util.Scanner;

public class KnowledgeBoat
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter 1 for letters and Unicode");
        System.out.println("Enter 2 to display the pattern");
        System.out.print("Enter your choice: ");
        int ch = in.nextInt();
        switch(ch) {
            case 1:
            System.out.println("Letters\tUnicode");
            for (int i = 65; i <= 90; i++)
                System.out.println((char)i + "\t" + i);
            break;
            
            case 2:
            for (int i = 1; i <= 5; i++) {
                for (int j = 1; j <= i; j++)
                    System.out.print(j + " ");
                System.out.println();
            }
            break;
            
            default:
            System.out.println("Wrong choice");
            break;
        }
    }
}
Output
BlueJ output of KnowledgeBoat.java
BlueJ output of KnowledgeBoat.java

Question 6

Write a program to input 15 integer elements in an array and sort them in ascending order using the bubble sort technique.

Answer

import java.util.Scanner;

public class KboatBubbleSort
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = 15;
        int arr[] = new int[n];
        
        System.out.println("Enter the elements of the array:");
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        
        //Bubble Sort
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = t;
                }
            } 
        }
        
        System.out.println("Sorted Array:");
        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
Output
BlueJ output of KboatBubbleSort.java

Question 7

Design a class to overload a function series( ) as follows:

(a) void series (int x, int n) – To display the sum of the series given below:

x1 + x2 + x3 + .......... xn terms

(b) void series (int p) – To display the following series:

0, 7, 26, 63 .......... p terms

(c) void series () – To display the sum of the series given below:

1/2 + 1/3 + 1/4 + .......... 1/10

Answer

public class KboatOverloadSeries
{
    void series(int x, int n) {
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += Math.pow(x, i);
        }
        System.out.println("Sum = " + sum);
    }

    void series(int p) {
        for (int i = 1; i <= p; i++) {
            int term = (int)(Math.pow(i, 3) - 1);
            System.out.print(term + " ");
        }
        System.out.println();
    }

    void series() {
        double sum = 0.0;
        for (int i = 2; i <= 10; i++) {
            sum += 1.0 / i;
        }
        System.out.println("Sum = " + sum);
    }
}
Output
BlueJ output of KboatOverloadSeries.java
BlueJ output of KboatOverloadSeries.java
BlueJ output of KboatOverloadSeries.java

Question 8

Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting with a letter 'A'.

Example:

Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.

Sample Output: Total number of words starting with letter 'A' = 4

Answer

import java.util.Scanner;

public class WordsWithLetterA
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a string: ");
        String str = in.nextLine();
        str = " " + str; //Add space in the begining of str
        int c = 0;
        int len = str.length();
        str = str.toUpperCase();
        for (int i = 0; i < len - 1; i++) {
            if (str.charAt(i) == ' ' && str.charAt(i + 1) == 'A')
                c++;
        }
        System.out.println("Total number of words starting with letter 'A' = " + c);
    }
}
Output
BlueJ output of WordsWithLetterA.java

Question 9

A tech number has even number of digits. If the number is split in two equal halves, then the square of sum of these halves is equal to the number itself. Write a program to generate and print all four digits tech numbers.

Example:

Consider the number 3025

Square of sum of the halves of 3025 = (30 + 25)2
= (55)2
= 3025 is a tech number.

Answer

public class TechNumbers
{
    public static void main(String args[]) {
        for (int i = 1000; i <= 9999; i++) {
            int secondHalf = i % 100;
            int firstHalf = i / 100;
            int sum = firstHalf + secondHalf;
            if (i == sum * sum)
                System.out.println(i);
        }
    }
}
Output
BlueJ output of TechNumbers.java
PrevNext