861-22-3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

ICSE SEMESTER 2 EXAMINATION

SAMPLE PAPER - 3
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.

SECTION A
(Attempt all questions.)

Section-A (Attempt all questions)


Question 1.
Choose the correct answers to the questions from the given options. (Do not copy the question, write
the correct answer only)
(i) Which feature can be implemented using encapsulation?
(a) Inheritance (c) Polymorphism
(b) Abstraction (d) Overloading
(ii) If String x = “Computer”; String y = “Applications”;
What do the following function returns ?
System.out.println(x.equals(y));
(a) true (b) false (c) 9 (d) Computer
(iii) The output of the statement, when executed : System.out.println(“Object Oriented”.length()); is :
(a) 16 (b) 17 (c) 15 (d) 19
(iv) Predict the output
String str = “Computer Applications” + 1 + 0;
System.out.println(“Understanding” + str);
(a) UnderstandingComputer Applications10 (c) Computer Applications01
(b) understandingcomputer applications10 (d) Computer Applications
(v) Predict output
boolean p;
p = (“BLUEJ”.length() > “bluej”.length()) ? true: false;
(vi) Output of the following code is :
String arr[]= {“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”, “JAIPUR”};
System.out.println(arr[0].length() > arr[3].length()); System.out.print(arr[4].substring(0,3));
(a) false JAI (b) false (c) JAI (d) JA
(vii) Predict output
String str1 = “Information Technology”; String str2 = “information technology”; boolean p = str1.
equalsIgnoreCase(str2); System.out.println(“The result is “ + p);
(a) “Information Technology” (c) true
(b) “information technology” (d) false
(viii) Which of these access specifiers must be used for main() method?
(a) private (c) protected
(b) public (d) none of the mentioned
(ix) Which of these is used as a default for a member of a class if no access specifier is used for it?
(a) private
(b) public
(c) public, within its own package
(d) protected
(x) Given s1=”computer” , s2=”Computer” , The statements
(i) s1.equalsIgnoreCase(s2) and (ii) s1.equals(s2)will return
(a) True,true (b) False,false (c) true,false (d) false,true

Section-B (Attempt any four questions)


Question 2.
Define a class to accept a sentence and display those words that begin with a vowel. Sample Input : A
quick brown fox jumps over a lazy dog.
Sample Output: A over a
Question 3.
Write a program that reads a long number, counts and displays the occurrences of each digit in it.
Question 4.
Write a program in Java to accept a word/a String and display the new string after removing all the
vowels present in it.
Sample Input: COMPUTER APPLICATIONS
Sample Output: CMPTR PPLCTNS
Question 5.
Define a class in Java to enter a String/Sentence and display the longest word and the length of the
longest word present in the String.
Sample Input: “Sir Garry Sobers is one of the legends in InternationalCricket”
Sample Output : The longest word: InternationalCricket: The length of the word: 20
Question 6.
Define a class in Java to store 20 numbers in a Single Dimensional Array. Display the numbers which
are composite.
Sample Input:
n[0] n[1] n[2] n[3] n[4] n[5] ... n[16] n[17] n[18] n[19]
45 65 77 71 90 67 ... 82 19 31 52
Sample Output: 45,65,77,90,82,52
Question 7.
Define a class in Java to accept a word and display the ASCII code of each character of the word.
Sample Input: BLUEJ
Sample Output:
ASCII of B = 66
ASCII of L = 76
ASCII of U = 85
ASCII of E = 69
ASCII of J = 74

Answers

Section-A
Answer 1.
(i) (b) Abstraction
Explanation :
Data abstraction can be achieved by using encapsulation. We can hide the operation and structure of
actual program from the user and can show only required information by the user.
(ii) (b) false
Explanation :
As strings x and y are not equal so x.equals(y) returns false.
(iii) (c) 15
Explanation :
The length() function returns the number of characters in a String.
(iv) (a) Understanding Computer Applications10
Explanation :
In the first line, + operator concatenates 1 and 0 to the end of “Computer Applications” so str becomes
“Computer Applications10”.
“UnderstandingComputer Applications10” to the console.
(v) false
Explanation :
Both “BLUEJ” and “bluej” have the same length 5. So, condition of ternary operator is false and false is
assigned to boolean variable p.
(vi) (a) false
JAI
Explanation :

As length of the string “DELHI” is less than that of “LUCKNOW” so first output is false. arr[4].
substring(0,3) will return the substring of “JAIPUR” starting at index 0 till index 2 (i.e. 3 - 1 = 2).
(vii) The result is true
Explanation :

str1.equalsIgnoreCase(str2) will do a case insensitive comparison of str1 and str2. As both strings contain
the same characters if we ignore the case so it returns true which is stored in boolean variable p.
(viii) (b) public
Explanation :

main() method must be specified public as it called by Java run time system, outside of the program.
If no access specifier is used then by default member is public within its own package and cannot be
accessed by Java run time system.
(ix) (a) private

Explanation :
When we pass an argument by call-by-value a copy of argument is made into the formal parameter of
the subroutine and changes made on parameters of subroutine have no effect on original argument,
they remain the same.
(x) (c) true, false
Explanation :
s1.equalsIgnoreCase(s2) compares the two strings without considering the case, hence returns true.
s1.equals(s2) compares the two strings considering the case, hence returns false. So output is true,
false :

Section-B
Answer 2.
import java.util. Scanner;
public class Vowelwords
{
public static void main(String[] args)
{
String sen=””,word=””; int i;
char ch;
Scanner sc=new Scanner(System.in); sen=sc.nextLine();
for(i=0;i< sen.length();i++)
{
if (sen. charAt(i)!=’ ‘)
{
word+=sen.charAt(i);
}
else
{
ch=word. charAt(0);
if (ch==’a’ || ch==’e’ || ch==’i’ || ch==’o’ || ch==’u’)
System.out.println(word);
word=””;
}
}
}
}
Answer 3.
import java.util.Scanner;
public class NumberOccurance
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print(“Enter a number: “);

long num = in.nextLong();


int dCount[] = new int[10];
while (num != 0)
{
int d = (int)(num % 10);
dCount[d] = dCount[d] + 1;
num /= 10;
}
System.out.println(“Digit\tOccurence”);
for (int i = 0; i < 10; i++)
{
if (dCount[i] != 0)
{
System.out.println(i + “\t” + dCount[i]);
}
}
}
}
Answer 4.
import java.util.Scanner;
public class VowelRemoval
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a word or sentence:”); String str = in.nextLine();

int len = str.length(); String newStr = “”;

for (int i = 0; i < len; i++)


{
char ch = Character.toUpperCase(str.charAt(i)); if (ch == ‘A’ || ch == ‘E’ ||
ch == ‘I’ || ch == ‘O’ || ch == ‘U’)
{
continue;
}

newStr = newStr + ch;


}
System.out.println(“String with vowels removed”); System.out.println(newStr);
}
}
Answer 5.
import java.util.Scanner;
public class LongestWord
{
public static void main(String args[])

{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a word or sentence:”); String str = in.nextLine();

str += “ “; //Add space at end of


string String word = “”, lWord = “”;
int len = str.length();

for (int i = 0; i < len; i++)


{
char ch =
str.charAt(i); if (ch == ‘ ‘)
{

if (word.length() >
lWord.length()) lWord =
word;

word = “”;
}
else
{
word += ch;
}
}
System.out.println(“The longest word: “ + lWord + “: The length of the word: “ + lWord.
length());
}
}
Answer 6.
import java.util.Scanner;
public class CompositeNumbers
{
public static void main(String args[])
{
Scanner in = new
Scanner(System.in);
int arr[] = new int[20];
System.out.println(“Enter 20 numbers”); for (int i = 0; i < arr.length; i++)
{
arr[i] = in.nextInt();
}

System.out.println(“Composite Numbers:”); for (int i = 0; i < arr.length; i++)

int c = 0;

for (int j = 1; j <= arr[i]; j++)


{
if (arr[i] % j == 0)
{
c++;
}
}
if (c != 2)
System.out.print(arr[i] + “, “);
}
}
}
Answer 7.
import java.util.Scanner;
public class ASCIICode
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println(“Enter a word:”);
String word = in.nextLine();
int len = word.length();
for (int i = 0; i < len; i++)
{
char ch = word.charAt(i);
System.out.println(“ASCII of “ + ch
+ “ = “ + (int)ch);
}
}
}


You might also like