You are on page 1of 11

ICSE J

Java for Class X Computer Applications

Menu

ICSE Class 10 Computer Applications ( Java ) 2012 Solved Question Paper


8 Replies

COMPUTER APPLICATIONS
(Theory )
(Two Hours)

Answers to this Paper must be written on the paper provided separately.


You will not be allowed to write during the first 15 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.
This Paper is divided into two Sections.
Attempt all questions from Section A and any four questions from Section B. The intended marks for questions or parts of questions are
given in brackets [ ].

SECTION A (40 Marks)

Attempt all questions.

Question 1

(a) Give one example each of a primitive data type and a composite data type. [2]
Ans. Primitiv e Data Ty pes by te, short, int, long, float, double, char, boolean
Composite Data Ty pe Class, Array , Interface

(b) Give one point of difference between unary and binary operators. [2]
Ans. A unary operator requires a single operand whereas a binary operator requires two operands.
Examples of Unary Operators Increment ( ++ ) and Decrement ( ) Operators
Examples of Binary Operators +, -, *, /, %

(c) Differentiate between call by value or pass by value and call by reference or pass by reference. [2]
Ans. In call by v alue, a copy of the data item is passed to the method which is called whereas in call by reference, a reference to the
original data item is passed. No copy is made. Primitiv e ty pes are passed by v alue whereas reference ty pes are passed by reference.

(d) Write a Java expression for (under root of 2as+u2) [2]


Ans. Math.sqrt ( 2 * a * s + Math.pow ( u, 2 ) )
( or )
Math.sqrt ( 2 * a * s + u * u )

(e) Name the types of error (syntax, runtime or logical error) in each case given below:
(i) Division by a variable that contains a value of zero.
(ii) Multiplication operator used when the operation should be division.
(iii) Missing semicolon. [2]
Ans.
(i) Runtime Error

converted by W eb2PDFConvert.com
(ii) Logical Error
(iii) Sy ntax Error

Question 2

(a)Create a class with one integer instance variable. Initialize the variable using:
(i) default constructor
(ii) parameterized constructor. [2]
Ans.

1 public class Integer {


2
3 int x;
4
5 public Integer() {
6 x = 0;
7 }
8
9 public Integer(int num) {
10 x = num;
11 }
12 }

(b)Complete the code below to create an object of Scanner class.


Scanner sc = ___________ Scanner( ___________ ) [2]
Ans. Scanner sc = new Scanner ( Sy stem.in )

(c) What is an array? Write a statement to declare an integer array of 10 elements. [2]
Ans. An array is a reference data used to hold a set of data of the same data ty pe. The following statement declares an integer array of
10 elements -
int arr[] = new int[10];

(d) Name the search or sort algorithm that:


(i) Makes several passes through the array, selecting the next smallest item in the array each time and placing it where it
belongs in the array.
(ii) At each stage, compares the sought key value with
2 the key value of the middle element of the array. [2]
Ans. (i) Selection Sort Like
(ii) Binary Search

(e) Differentiate between public and private modifiers for members of a class. [2]
Ans. Variables and Methods whwith the public access modie the class also.

Question 3

(a) What are the values of x and y when the following statements are executed? [2]

1 int a = 63, b = 36;


2 boolean x = (a < b ) ? true : false; int y= (a > b ) ? a : b ;

Ans. x = false
y = 63

(b) State the values of n and ch [2]

1 char c = 'A':
2 int n = c + 1;

Ans. The ASCII v alue for A is 65. Therefore, n will be 66.

(c) What will be the result stored in x after evaluating the following expression? [2]

converted by W eb2PDFConvert.com
1 int x=4;
2 x += (x++) + (++x) + x;

Ans. x = x + (x++) + (++x) + x


x=4+4+6+6
x = 20

(d) Give the output of the following program segment: [2]

1 double x = 2.9, y = 2.5;


2 System.out.println(Math.min(Math.floor(x), y));
3 System.out.println(Math.max(Math.ceil(x), y));

Ans.
2.0
3.0
Explanation : Math.min(Math.floor(x), y ) = Math.min ( 2.0, 2.5 ) = 2.0
Math.max(Math.ceil(x), y )) = Math.max ( 3.0, 2.5 ) = 3.0

(e) State the output of the following program segment. [2]

1 String s = "Examination";
2 int n = s.length();
3 System.out.println(s.startsWith(s.substring(5, n)));
4 System.out.println(s.charAt(2) == s.charAt(6));

Ans.
false
true
Explanation : n = 11
s.startsWith(s.substring(5, n)) = s.startsWith ( nation ) = false
( s.charAt(2) == s.charAt(6) ) = ( a== a ) = true

(f) State the method that:


(i) Converts a string to a primitive float data type
(ii) Determines if the specified character is an uppercase character [2]
Ans. (i) Float.parseFloat(String)
(ii) Character.isUpperCase(char)

(g) State the data type and values of a and b after the following segment is executed.[2]

1 String s1 = "Computer", s2 = "Applications";


2 a = (s1.compareTo(s2));
3 b = (s1.equals(s2));

Ans. Data ty pe of a is int and b is boolean.


ASCII v alue of C is 67 and A is 65. So compare giv es 67-65 = 2.
Therefore a = 2
b = false

(h) What will the following code output? [2]

1 String s = "malayalam";
2 System.out.println(s.indexOf('m'));
3 System.out.println(s.lastIndexOf('m'));

Ans.
0
8

(i) Rewrite the following program segment using while instead of for statement [2]

converted by W eb2PDFConvert.com
1 int f = 1, i;
2 for (i = 1; i <= 5; i++) {
3 f *= i;
4 System.out.println(f);
5 }

Ans.

1 int f = 1, i = 1;
2 while (i <= 5) {
3 f *= i;
4 System.out.println(f);
5 i++;
6 }

(j) In the program given below, state the name and the value of the
(i) method argument or argument variable
(ii) class variable
(iii) local variable
(iv) instance variable [2]

1 class myClass {
2
3 static int x = 7;
4 int y = 2;
5
6 public static void main(String args[]) {
7 myClass obj = new myClass();
8 System.out.println(x);
9 obj.sampleMethod(5);
10 int a = 6;
11 System.out.println(a);
12 }
13
14 void sampleMethod(int n) {
15 System.out.println(n);
16 System.out.println(y);
17 }
18 }

Ans. (i) name = n v alue =5


(ii) name = y v alue = 7
(iii) name = a v alue = 6
(iv ) name = obj v alue = new My Class()

SECTION B (60 MARKS)

Attempt any four questions from this Section.


The answers in this Section should consist of the Programs in either Blue J environment or any program environment with Java as the base.
Each program should be written using Variable descriptions/Mnemonic Codes so that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4

Define a class called Library with the following description:


Instance v ariables/data members:
Int acc_num stores the accession number of the book
String title stores the title of the book stores the name of the author
Member Methods:
(i) v oid input() To input and store the accession number, title and author.
(ii)v oid compute To accept the number of day s late, calculate and display and fine charged at the rate of Rs.2 per day .
(iii) v oid display () To display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the abov e member methods. [ 15]

Ans.

converted by W eb2PDFConvert.com
1 public class Library {
2
3 int acc_num;
4 String title;
5 String author;
6
7 public void input() throws IOException {
8 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9 System.out.print("Enter accession number: ");
10 acc_num = Integer.parseInt(br.readLine());
11 System.out.print("Enter title: ");
12 title = br.readLine();
13 System.out.print("Enter author: ");
14 author = br.readLine();
15 }
16
17 public void compute() throws IOException {
18 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19 System.out.print("Enter number of days late: ");
20 int daysLate = Integer.parseInt(br.readLine());;
21 int fine = 2 * daysLate;
22 System.out.println("Fine is Rs " + fine);
23 }
24
25 public void display() {
26 System.out.println("Accession Number\tTitle\tAuthor");
27 System.out.println(acc_num + "\t" + title + "\t" + author);
28 }
29
30 public static void main(String[] args) throws IOException {
31 Library library = new Library();
32 library.input();
33 library.compute();
34 library.display();
35 }
36 }

Question 5

Giv en below is a hy pothetical table showing rates of Income Tax for male citizens below the age of 65 y ears:

Taxable Income (TI) in Income Tax in

Does not exceed 1,60,000 Nil

Is greater than 1,60,000 and less than or equal to 5,00,000 ( TI 1,60,000 ) * 10%

Is greater than 5,00,000 and less than or equal to 8,00,000 [ (TI - 5,00,000 ) *20% ] + 34,000

Is greater than 8,00,000 [ (TI - 8,00,000 ) *30% ] + 94,000

Write a program to input the age, gender (male or female) and Taxable Income of a person.If the age is more than 65 y ears or the
gender is female, display wrong category *.
If the age is less than or equal to 65 y ears and the gender is male, compute and display the Income Tax pay able as per the table giv en
abov e. [15]
Ans.

1 import java.util.Scanner;
2
3 public class IncomeTax {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 System.out.print("Enter age: ");
8 int age = scanner.nextInt();
9 System.out.print("Enter gender: ");
10 String gender = scanner.next();
11 System.out.print("Enter taxable income: ");
12 int income = scanner.nextInt();
13 if (age > 65 || gender.equals("female")) {
14 System.out.println("Wrong category");
15 } else {
16 double tax;
17 if (income <= 160000) { tax = 0; } else if (income > 160000 &&
income <= 500000) { tax = (income - 160000) * 10 / 100; } else if (income >=
500000 && income <= 800000) {
18 tax = (income - 500000) * 20 / 100 + 34000;

converted by W eb2PDFConvert.com
19 } else {
20 tax = (income - 800000) * 30 / 100 + 94000;
21 }
22 System.out.println("Income tax is " + tax);
23 }
24 }
25 }

Question 6

Write a program to accept a string. Conv ert the string to uppercase. Count and output the number of double letter sequences that
exist in the string.
Sample Input: SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE
Sample Output: 4 [ 15]

Ans.

1 import java.util.Scanner;
2
3 public class StringOperations {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 System.out.print("Enter a String: ");
8 String input = scanner.nextLine();
9 input = input.toUpperCase();
10 int count = 0;
11 for (int i = 1; i < input.length(); i++) {
12 if (input.charAt(i) == input.charAt(i - 1)) {
13 count++;
14 }
15 }
16 System.out.println(count);
17 }
18 }

Question 7

Design a class to ov erload a function poly gon() as follows:


(i) v oid poly gon(int n, char ch) : with one integer argument and one character ty pe argument that draws a filled square of side n using
the character stored in ch.
(ii) v oid poly gon(int x, int y ) : with two integer arguments that draws a filled rectangle of length x and breadth y , using the sy mbol @
(iii)v oid poly gon( ) : with no argument that draws a filled triangle shown below.

Example:
(i) Input v alue of n=2, ch=O
Output:
OO
OO
(ii) Input v alue of x=2, y =5
Output:
@@@@@
@@@@@
(iii) Output:
*
**
*** [15]

Ans.

1 public class Overloading {


2
3 public void polygon(int n, char ch) {
4 for (int i = 1; i <= n; i++) {
5 for (int j = 1; j <= n; j++) {
6 System.out.print(ch);
7 }

converted by W eb2PDFConvert.com
8 System.out.println();
9 }
10 }
11
12 public void polygon(int x, int y) {
13 for (int i = 1; i <= x; i++) {
14 for (int j = 1; j <= y; j++) {
15 System.out.print("@");
16 }
17 System.out.println();
18 }
19 }
20
21 public void polygon() {
22 for (int i = 1; i <= 3; i++) {
23 for (int j = 1; j <= i; j++) {
24 System.out.print("*");
25 }
26 System.out.println();
27 }
28 }
29 }

Question 8

Using the switch statement, writw a menu driv en program to:


(i) Generate and display the first 10 terms of the Fibonacci series 0,1,1,2,3,5.The first two Fibonacci numbers are 0 and 1, and each
subsequent number is the sum of the prev ious two.
(ii)Find the sum of the digits of an integer that is input.
Sample Input: 15390
Sample Output: Sum of the digits=18
For an incorrect choice, an appropriate error message should be display ed [15]

Ans.

1 import java.util.Scanner;
2
3 public class Menu {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 System.out.println("Menu");
8 System.out.println("1. Fibonacci Sequence");
9 System.out.println("2. Sum of Digits");
10 System.out.print("Enter choice: ");
11 int choice = scanner.nextInt();
12 switch (choice) {
13 case 1:
14 int a = 0;
15 int b = 1;
16 System.out.print("0 1 ");
17 for (int i = 3; i <= 10; i++) { int c = a + b;
System.out.print(c + " "); a = b; b = c;
} break; case 2: System.out.print("Enter a number:
"); int num = scanner.nextInt(); int sum = 0; while (num
> 0) {
18 int rem = num % 10;
19 sum = sum + rem;
20 num = num / 10;
21 }
22 System.out.println("Sum of digits is " + sum);
23 break;
24 default:
25 System.out.println("Invalid Choice");
26 }
27 }
28 }

Question 9

Write a program to accept the names of 10 cities in a single dimension string array and their STD (Subscribers Trunk Dialing) codes in
another single dimension integer array . Search for a name of a city input by the user in the list. If found, display Search Successful and
print the name of the city along with its STD code, or else display the message Search Unsuccessful, No such city in the list. [15]

Ans.

converted by W eb2PDFConvert.com
1 import java.util.Scanner;
2
3 public class Cities {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 String[] cities = new String[10];
8 int[] std = new int[10];
9 for (int i = 0; i < 10; i++) {
10 System.out.print("Enter city: ");
11 cities[i] = scanner.next();
12 System.out.print("Enter std code: ");
13 std[i] = scanner.nextInt();
14 }
15 System.out.print("Enter city name to search: ");
16 String target = scanner.next();
17 boolean searchSuccessful = false;
18 for (int i = 0; i < 10; i++) {
19 if (cities[i].equals(target)) {
20 System.out.println("Search successful");
21 System.out.println("City : " + cities[i]);
22 System.out.println("STD code : " + std[i]);
23 searchSuccessful = true;
24 break;
25 }
26 }
27 if (!searchSuccessful) {
28 System.out.println("Search Unsuccessful, No such city in the list");
29 }
30 }
31 }

Jav a Program to Calculate Compound Interest Jav a Program to find the Factorial of a Number

8 thoughts on ICSE Class 10 Computer Applications ( Java ) 2012 Solved Question Paper

gaurav
January 24, 2014 at 3:32 pm

good

Reply

annu
February 25, 2014 at 4:17 pm

v ery well done ,thanx a lot for clearing my doubts

Reply

simran shakya
March 13, 2014 at 5:25 am

AWESOME .THANKX FOR CLEARING MY DOUBTS

converted by W eb2PDFConvert.com
Reply

Anshul
May 21, 2014 at 9:35 am

1 class Assignment_Number_8 {
2
3 void polygon(int n, char ch) {
4 for (int r = 1; r <= n; r++) {
5 for (int c = 1; c <= n; c++) {
6 System.out.print(ch);
7 }
8 System.out.println();
9 }
10 }
11
12 void polygon(int x, int y) {
13 for (int r = 1; r <= x; r++) {
14 for (int c = 1; c <= y; c++) {
15 System.out.print("@");
16 }
17 System.out.println();
18 }
19 }
20
21 void polygon() {
22 for (int r = 1; r <= 2; r++) {
23 for (int c = 1; c <= 3; c++) {
24 System.out.print("*");
25 }
26 System.out.println();
27 }
28 }
29 }

when i run the v oid poly gon(int n, int ch) method of the abov e code the output is incorrect for all v alues of ch. Please help

Reply

ICSE Java Post author


May 25, 2014 at 11:52 am

We will be able to help y ou if y ou tell us what is the pattern that y ou want to print.

Zoha U mar
August 24, 2014 at 1:08 pm

Hey !My name is Zoha,Ill be giv ing the ICSE Examinations after this y ear,may be 2015.It was because of my parents wish that I was giv en
Computers as an additional subject but from that day till now,I am unable to understand it,from basic programs to complicated
functions,all hav e been out of my mind by now.Iv e nev er been to a coaching institute for such purpose but now as Iv e receiv ed much
less grades,Im thinking to giv e a special attention to it.I am a bright student by Gods grace,but I know,computers will decrease my
percentage.If any of y ou can help me with basic programming,Ill be extremely thankful to y ou people.The problem comes when when I
read the question,suppose it is giv en to write a program to identify an armstrong number,I get the thing but dont know what to write to
prov e the number is so,the basic part.PLEASE ANYONE HELP ME.YOU WILL BE BLESSED BY GOD THROUGHOUT YOUR LIFE.

Reply

converted by W eb2PDFConvert.com
ICSE Java Post author
August 24, 2014 at 4:28 pm

If y ou hav e any specific doubts, y ou can ask them on our forum http://www.icsejav a.com/answers/

Jithin Jose
February 17, 2015 at 12:05 pm

Hello,my name is jithin jose.i would like toask u a doubt.What is the may purpose of exception handling.
With this can we solv e all the erors comming in the program.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *
Name *

Email *

Website

CAPTCHA Code
*
Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del
datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Comment

converted by W eb2PDFConvert.com
Java is a registered trademark of Oracle. This site is in no way related to or endorsed by Oracle.

ICSE J Answers

Ask and Answer questions related to Java. Get help from experts and get all your doubts cleared!

Search

ICSE Java
2,054 likes

Like Page Share

Be the first of your friends to like this

(C) ICSE Jav a, All Rights Reserv ed

converted by W eb2PDFConvert.com

You might also like