ICSE Computer Applications 2022 Semester 2 Examination

SEMESTER 2 EXAMINATION
COMPUTER APPLICATIONS
Maximum Marks: 50
Time Allowed: One and a half hours
Answers to this paper must be written on the paper provided separately.
You will not be allowed to write during the first 10 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this paper is the time allowed for writing the answers.
Attempt all questions from Section A and any four questions from Section B.
The marks intended for questions are given in brackets [ ].

SECTION A
(Attempt all questions)

Question 1 [10]
Choose the correct answers to the questions from the given options. (Do not copy the question. Write the correct answer only)
(i) Return data type of isLetter(char) is ________.
(a) Boolean
(b) boolean
(c) bool
(d) char
(ii) Method that converts a character to uppercase is ________.
(a) toUpper()
(b) ToUpperCase()
(c) toUppercase()
(d) toUpperCase(char)
(iii) Give the output of the following String methods:
"SUCESS".indexOf('S') + "SUCESS".lastIndexOf('S')
(a) 0
(b) 5
(c) 6
(d) -5
(iv) Corresponding wrapper class of float data type is ________.
(a) FLOAT
(b) float
(c) Float
(d) Floating
(v) ________ class is used to convert a primitive data type to its corresponding object.
(a) String
(b) Wrapper
(c) System
(d) Math
(vi) Give the output of the following code:
System.out.println("Good".concat("Day"));
(a) GoodDay
(b) Good Day
(c) Goodday
(d) goodDay
(vii) A single dimensional array contains N elements. What will be the last subscript?
(a) N
(b) N - 1
(c) N - 2
(d) N + 1
(viii) The access modifier that gives least accessibility is:
(a) private
(b) public
(c) protected
(d) package
(ix) Give the output of the following code:
String A = "56.0", B = "94.0";
double C = Double.parseDouble(A);
double D = Double.parseDouble(B);
System.out.println((C + D));

(a) 100
(b) 150.0
(c) 100.0
(d) 150
(x) What will be the output of the following code?
System.out.println("Lucknow".substring(0, 4));
(a) Lucknow
(b) Lucks
(c) Luck
(d) luck

SECTION B
(Attempt any four questions from this section)

Question 2 [10]
Define a class to perform binary search on a list of integers given below, to search for an element input by the user. If it is found display the element along with its position, otherwise display the message "Search element not found".
2, 5, 7, 10, 15, 20, 29, 30, 46, 50

import java.util.Scanner;
class BinarySearch{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        int a[] = {2, 5, 7, 10, 15, 20, 29, 30, 46, 50};
        int low = 0;
        int high = a.length - 1;
        int mid = 0;
        System.out.print("Element to be searched: ");
        int s = Integer.parseInt(in.nextLine());
        while(low <= high){
            mid = (low + high) / 2;
            if(s == a[mid])
                break;
            else if(s < a[mid])
                high = mid - 1;
            else
                low = mid + 1;
        }
        if(low > high)
            System.out.println("Search element not found");
        else
            System.out.println(s + " found at position " + (mid + 1));
    }
}

Question 3 [10]
Define a class to declare a character array of size ten. Accept the characters into the array and display the characters with highest and lowest ASCII (American Standard Code for Information Interchange) value.
EXAMPLE:
INPUT:
'R', 'z', 'q', 'A', 'N', 'p', 'm', 'U', 'Q', 'F'
OUTPUT:
Character with highest ASCII value = z
Character with lowest ASCII value = A

import java.util.Scanner;
class MyArray{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        char a[] = new char[10];
        System.out.println("Enter 10 characters:");
        for(int i = 0; i < a.length; i++)
            a[i] = in.nextLine().charAt(0);
        char low = a[0];
        char high = a[0];
        for(int i = 1; i < a.length; i++){
            if(low > a[i])
                low = a[i];
            if(high < a[i])
                high = a[i];
        }
        System.out.println("Character with highest ACII value = " + high);
        System.out.println("Character with lowest ASCII value = " + low);
    }
}

Question 4 [10]
Define a class to declare an array of size twenty of double data type. Accept the elements into the array and perform the following:

  • Calculate and print the product of all the elements
  • Print the square of each element of the array

import java.util.Scanner;
class Calculate{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        double a[] = new double[20];
        double p = 1.0;
        System.out.println("Enter 20 numbers:");
        for(int i = 0; i < a.length; i++){
            a[i] = Double.parseDouble(in.nextLine());
            p *= a[i];
        }
        System.out.println("Product of all elements: " + p);
        System.out.println("Square of each element:");
        for(int i = 0; i < a.length; i++)
            System.out.println(a[i] * a[i]);
    }
}

Question 5 [10]
Define a class to accept a string and print the characters with the uppercase and lowercase reversed, but all the other characters should remain the same as before.
EXAMPLE:
INPUT: WelCoMe_2022
OUTPUT: wELcOmE_2022

import java.util.Scanner;
class Reversed{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the string: ");
        String s = in.nextLine();
        String t = "";
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(Character.isUpperCase(ch))
                t += Character.toLowerCase(ch);
            else
                t += Character.toUpperCase(ch);
        }
        System.out.println(t);
    }
}

Question 6 [10]
Define a class to declare an array to accept and store ten words. Display only those words which begin with the letter 'A' or 'a' and also end with the letter 'A' or 'a'.
EXAMPLE:
INPUT: Hari, Anita, Akash, Amrita, Alina, Devi, Rishab, John, Farha, AMITHA
OUTPUT:
Anita
Amrita
Alina
AMITHA

import java.util.Scanner;
class Display{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String a[] = new String[10];
        System.out.println("Enter 10 words:");
        for(int i = 0; i < a.length; i++)
            a[i] = in.next();
        System.out.println("Words that begin and end with A:");
        for(int i = 0; i < a.length; i++){
            char first = a[i].charAt(0);
            char last = a[i].charAt(a[i].length() - 1);
            if((first == 'A' || first == 'a') && (last == 'A' || last == 'a'))
                System.out.println(a[i]);
        }
    }
}

Question 7 [10]
Define a class to accept two strings of same length and form a new word in such a way that, the first character of the first word is followed by the first character of the second word and so on.
Example:
Input String 1: BALL
Input String 2: WORD
OUTPUT: BWAOLRLD

import java.util.Scanner;
class Arrange{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        System.out.print("Enter string 1: ");
        String s1 = in.nextLine();
        System.out.print("Enter string 2: ");
        String s2 = in.nextLine();
        if(s1.length() != s2.length()){
            System.out.println("Should be of the same length!");
            return;
        }
        String s3 = "";
        for(int i = 0; i < s1.length(); i++){
            s3 += s1.charAt(i);
            s3 += s2.charAt(i);
        }
        System.out.println(s3);
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory

Bank Inheritance Program ISC Specimen 2023 Theory