Icse J: ICSE Class 10 Computer Applications (Java) 2009 Solved Question Paper
Icse J: ICSE Class 10 Computer Applications (Java) 2009 Solved Question Paper
Skip to content
• Programs
• Question Papers
• Theory
• Theory Questions
• Answers (Forum)
Section A
Question 1:
(b) State the difference between a boolean literal and a character literal. [2]
Ans. i) A boolean literal can store one of two values – true and false. A character literal can store a
single Unicode character.
ii) The memory required by a boolean literal depends on the implementation. The memory required
by a character literal is 2 bytes.
(e) State one similarity and one difference between while and for loop. [2]
Ans. A while loop contains only a condition while a for loop contains initialization, condition and
iteration.
Question 2:
(a) Write the function prototype for the function “sum” that takes an integer variable (x) as its
argument and returns a value of float data type. [2]
Ans.
1 x = 1; y = 1;
2 if(n > 0)
3 {
4 x = x + 1;
5 y = y - 1;
6 }
What will be the value of x and y, if n assumes a value (i) 1 (ii) 0? [2]
Ans. i) 1 > 0 is true, so if block will be executed.
x=x+1=1+1=2
y=y–1=1–1=0
ii) 0 > 0 is false, so if block will not be executed and therefore, the values of x and y won’t change.
x=1
y=1
(c) Analyze the following program segment and determine how many times the body of loop will
be executed (show the working). [2]
1 x = 5; y = 50;
2 while(x<=y)
3 {
4 y=y/x;
5 System.out.println(y);
6 }
Ans.
(d) When there are multiple definitions with the same function name, what makes them
different from each other? [2]
Ans. The function prototype make multiple definitions of a function different from each other. Either
the number, type or order or arguments should be different for the functions having identical names.
(f) Give the output of the following code segment when (i) opn = ‘b’ (ii) opn = ‘x’ (iii) opn = ‘a’.
[3]
1 switch(opn)
2 {
3 case 'a':
4 System.out.println("Platform Independent");
5 break;
6 case 'b':
7 System.out.println("Object Oriented");
8 case 'c':
9 System.out.println("Robust and Secure");
10 break;
11 default:
12 System.out.println("Wrong Input");
13 }
1 Object Oriented
2 Robust and Secure
As there is no break statement for case ‘b’, statements in case ‘c’ will also be printed when opn = ‘b’.
ii) Output will be
1 Wrong Input
As ‘x’ doesn’t match with either ‘a’, ‘b’ or ‘c’, the default statement will be executed.
iii) Output will be
1 Platform Independent
(g) Consider the following code and answer the questions that follow: [4]
1 class academic
2 {
3 int x, y;
4 void access()
5 {
6 int a, b;
7 academic student = new academic();
8 System.out.println("Object created");
9 }
10 }
i) What is the object name of class academic?
ii) Name the class variables used in the program?
iii) Write the local variables used in the program.
iv) Give the type of function used and its name.
Ans. i) student
ii) x and y
iii) a and b
iv) Type: Non Static
Name: access
1 int x,c;
2 for(x=10,c=20;c>10;c=c-2)
3 x++;
Ans.
1 int x, c;
2 x = 10;
3 c = 20;
4 do {
5 x++;
6 c = c - 2;
7 } while (c > 10);
Section B
Question 4
An electronics shop has announced the following seasonal discounts on the purchase of certain items.
Write a program based on the above criteria to input name, address, amount of purchase and type of
purchase (L for Laptop and D for Desktop) by a customer. Compute and print the net amount to be
paid by a customer along with his name and address. [15]
Ans.
1 import java.util.Scanner;
2
3 public class Electronics {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 System.out.print("Enter name: ");
8 String name = scanner.nextLine();
9 System.out.print("Enter address: ");
10 String address = scanner.nextLine();
11 System.out.print("Enter type of purchase: ");
12 String type = scanner.nextLine();
13 System.out.print("Enter amount of purchase: ");
14 int amount = scanner.nextInt();
15 double discountRate = 0.0;
16 if (type.equals("L")) {
17 if (amount <= 25000) {
18 discountRate = 0;
19 } else if (amount >= 25001 && amount <= 57000) {
20 discountRate = 5.0;
21 } else if (amount >= 57001 && amount <= 100000) {
22 discountRate = 7.5;
23 } else if (amount > 100000) {
24 discountRate = 10.0;
25 }
26 } else if (type.equals("D")) {
27 if (amount <= 25000) {
28 discountRate = 5.0;
29 } else if (amount >= 25001 && amount <= 57000) {
30 discountRate = 7.6;
31 } else if (amount >= 57001 && amount <= 100000) {
32 discountRate = 10.0;
33 } else if (amount > 100000) {
34 discountRate = 15.0;
35 }
36 }
37 double discount = (discountRate / 100) * amount;
38 double netAmount = amount - discount;
39 System.out.println("Name: " + name);
40 System.out.println("Address: " + address);
41 System.out.println("Net Amount: " + netAmount);
42 }
43
44 }
Sample Output:
Question 5:
Write a program to generate a triangle or an inverted triangle till n terms based upon the user’s choice
of triangle to be displayed. [15]
Example 1
Input: Type 1 for a triangle and
type 2 for an inverted triangle
1
Enter the number of terms
5
Output:
1
22
333
4444
55555
Example 2:
Input: Type 1 for a triangle and
type 2 for an inverted triangle
2
Enter the number of terms
6
Output:
666666
55555
4444
333
22
1
Ans.
1 import java.util.Scanner;
2
3 public class Traingle {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 System.out.print("Type 1 for a triangle and type 2 for an
inverted triangle: ");
8 int choice = scanner.nextInt();
9 System.out.print("Enter number of terms: ");
10 int n = scanner.nextInt();
11 if (choice == 1) {
12 for (int i = 1; i <= n; i++) {
13 for (int j = 1; j <= i; j++) {
14 System.out.print(i + " ");
15 }
16 System.out.println();
17 }
18 } else if (choice == 2) {
19 for (int i = n; i >= 1; i--) {
20 for (int j = 1; j <= i; j++) {
21 System.out.print(i + " ");
22 }
23 System.out.println();
24 }
25 }
26 }
27
28 }
Question 6:
Write a program to input a sentence and print the number of characters found in the longest word of
the given sentence.
For example is S = “India is my country” then the output should be 7. [15]
Ans.
1 import java.util.Scanner;
2
3 public class LongestWord {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 System.out.print("Enter a sentence: ");
8 String sentence = scanner.nextLine();
9 int longest = 0;
10 int currentWordLength = 0;
11 for (int i = 0; i < sentence.length(); i++) {
12 char ch = sentence.charAt(i);
13 if (ch == ' ') {
14 if (currentWordLength > longest) {
15 longest = currentWordLength;
16 }
17 currentWordLength = 0;
18 } else {
19 currentWordLength++;
20 }
21 }
22 if (currentWordLength > longest) {
23 longest = currentWordLength;
24 }
25 System.out.println("The longest word has " + longest + "
characters");
26 }
27 }
Question 7:
i) void num_calc(int num, char ch) with one integer argument and one character argument, computes
the square of integer argument if choice ch is ‘s’ otherwise finds its cube.
ii) void num_calc(int a, int b, char ch) with two integer arguments and one character argument. It
computes the product of integer arguments if ch is ‘p’ else adds the integers.
iii) void num_calc(String s1, String s2) with two string arguments, which prints whether the strings
are equal or not.
Ans.
b) GCD (Greatest Common Divisor) of two integers is calculated by continued division method.
Divide the larger number by the smaller; the remainder then divides the previous divisor. The process
is repeated till the remainder is zero. The divisor then results the GCD.
Ans.
1 import java.util.Scanner;
2
3 public class Menu {
4
5 public boolean isBuzzNumber(int num) {
6 int lastDigit = num % 10;
7 int remainder = num % 7;
8 if (lastDigit == 7 || remainder == 0) {
9 return true;
10 } else {
11 return false;
12 }
13 }
14
15 public int gcd(int a, int b) {
16 int dividend, divisor;
17 if (a > b) {
18 dividend = a;
19 divisor = b;
20 } else {
21 dividend = b;
22 divisor = a;
23 }
24 int gcd;
25 while (true) {
26 int remainder = dividend % divisor;
27 if (remainder == 0) {
28 gcd = divisor;
29 break;
30 }
31 dividend = divisor;
32 divisor = remainder;
33 }
34 return gcd;
35 }
36
37 public void menu() {
38 Scanner scanner = new Scanner(System.in);
39 System.out.println("1. Buzz Number");
40 System.out.println("2. GCD");
41 System.out.print("Enter your choice: ");
42 int choice = scanner.nextInt();
43 if (choice == 1) {
44 System.out.print("Enter a number: ");
45 int num = scanner.nextInt();
46 if (isBuzzNumber(num)) {
47 System.out.println(num + " is a buzz number");
48 } else {
49 System.out.println(num + " is not a buzz number");
50 }
51 } else if (choice == 2) {
52 System.out.print("Enter two numbers: ");
53 int num1 = scanner.nextInt();
54 int num2 = scanner.nextInt();
55 int gcd = gcd(num1, num2);
56 System.out.println("GCD: " + gcd);
57 } else {
58 System.out.println("Invalid Choice");
59 }
60 }
61
62 public static void main(String[] args) {
63 Menu menu = new Menu();
64 menu.menu();
65 }
66
67 }
Sample Output 1:
1 1. Buzz Number
2 2. GCD
3 Enter your choice: 1
4 Enter a number: 49
5 49 is a buzz number
Sample Output 2:
1 1. Buzz Number
2 2. GCD
3 Enter your choice: 2
4 Enter two numbers: 49 77
5 GCD: 7
Question 9
The annual examination results of 50 students in a class is tabulated as follows.
Write a program to read the data, calculate and display the following:
Ans.
1 import java.util.Scanner;
2
3 public class StudentMarks {
4
5 public static void main(String[] args) {
6 Scanner scanner = new Scanner(System.in);
7 int[] rno = new int[50];
8 int[] subjectA = new int[50];
9 int[] subjectB = new int[50];
10 int[] subjectC = new int[50];
11 double[] average = new double[50];
12 for (int i = 0; i < 50; i++) {
13 System.out.print("Enter Roll No: ");
14 rno[i] = scanner.nextInt();
15 System.out.print("Enter marks in subject A: ");
16 subjectA[i] = scanner.nextInt();
17 System.out.print("Enter marks in subject B: ");
18 subjectB[i] = scanner.nextInt();
19 System.out.print("Enter marks in subject C: ");
20 subjectC[i] = scanner.nextInt();
21 average[i] = (subjectA[i] + subjectB[i] + subjectC[i])
/ 3.0;
22 }
23 System.out.println("Roll No - Average");
24 for (int i = 0; i < 50; i++) {
25 System.out.println(rno[i] + " - " + average[i]);
26 }
27 System.out.println("Students with average greater than
80");
28 for (int i = 0; i < 50; i++) {
29 if (average[i] > 80) {
30 System.out.println(rno[i] + " - " + average[i]);
31 }
32 }
33 System.out.println("Students with average less than 40");
34 for (int i = 0; i < 50; i++) {
35 if (average[i] < 40) {
36 System.out.println(rno[i] + " - " + average[i]);
37 }
38 }
39 }
40 }
Sample Output:
1 run:
2 Enter Roll No: 1
3 Enter marks in subject A: 100
4 Enter marks in subject B: 100
5 Enter marks in subject C: 97
6 Enter Roll No: 2
7 Enter marks in subject A: 10
8 Enter marks in subject B: 10
9 Enter marks in subject C: 10
10 Enter Roll No: 3
11 Enter marks in subject A: 50
12 Enter marks in subject B: 50
13 Enter marks in subject C: 50
14 ...
15 Roll No - Average
16 1 - 99.0
17 2 - 10.0
18 3 - 50.0
19 ...
20 Students with average greater than 80
21 1 - 99.0
22 Students with average less than 40
23 2 - 10.0
24 ...
Post navigation
← ICSE Class 10 Computer Applications ( Java ) 2010 Solved Question Paper this keyword →
In section A, ques g,
Since x and y haven’t been declared using keyword static,Aren’t they instance variables?
Reply ↓
Leave a Reply
Your email address will not be published. Required fields are marked *
Name *
Email *
Website
CAPTCHA Image
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
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!