0% found this document useful (0 votes)
33 views179 pages

Solved CompSci QP From 2010 2019 1735703705

The document contains solved question papers for ICSE Class 10 Computer Applications from 2010, covering various topics such as Java programming, data types, exception handling, and object-oriented concepts. It includes definitions, code snippets, and programming exercises with explanations and outputs. Additionally, it features practical programming tasks like binary search, class creation, and discount calculations.

Uploaded by

rekhamuthu731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views179 pages

Solved CompSci QP From 2010 2019 1735703705

The document contains solved question papers for ICSE Class 10 Computer Applications from 2010, covering various topics such as Java programming, data types, exception handling, and object-oriented concepts. It includes definitions, code snippets, and programming exercises with explanations and outputs. Additionally, it features practical programming tasks like binary search, class creation, and discount calculations.

Uploaded by

rekhamuthu731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 179

Solved 2010 Question Paper ICSE Class 10 Computer

Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/k1V5R/year-
2010

2010

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) Define the term Bytecode.

Answer

Java compiler converts Java source code into an intermediate binary code called
Bytecode. Bytecode can't be executed directly on the processor. It needs to be converted
into Machine Code first.

(b) What do you understand by type conversion? How is implicit conversion


different from explicit conversion?

Answer

The process of converting one predefined type into another is called type conversion. In
an implicit conversion, the result of a mixed mode expression is obtained in the higher
most data type of the variables without any intervention by the user. For example:

int a = 10;
float b = 25.5f, c;
c = a + b;

In case of explicit type conversion, the data gets converted to a type as specified by the
programmer. For example:

int a = 10;
double b = 25.5;
float c = (float)(a + b);

(c) Name two jump statements and their use.

Answer

break statement, it is used to jump out of a switch statement or a loop. continue


statement, it is used to skip the current iteration of the loop and start the next iteration.

1/20
(d) What is Exception? Name two exception handling blocks.

Answer

An exception is an event, which occurs during the execution of a program, that disrupts
the normal flow of the program's instructions. Two exception handling blocks are try and
catch.

(e) Write two advantages of using functions in a program.

Answer

1. Methods help to manage the complexity of the program by dividing a bigger


complex task into smaller, easily understood tasks.
2. Methods help with code reusability.

Question 2

(a) State the purpose and return data type of the following String functions:

1. indexOf()
2. compareTo()

Answer

1. indexOf() returns the index within the string of the first occurrence of the specified
character or -1 if the character is not present. Its return type is int.
2. compareTo() compares two strings lexicographically. Its return type is int.

(b) What is the result stored in x, after evaluating the following expression?

int x = 5;
x = x++ * 2 + 3 * --x;

Answer

x = x++ * 2 + 3 * --x
⇒x=5*2+3*5
⇒ x = 10 + 15
⇒ x = 25

(c) Differentiate between static and non-static data members.

Answer

Static Data Members Non-Static Data Members

They are declared using keyword 'static'. They are declared without using keyword
'static'.

2/20
Static Data Members Non-Static Data Members

All objects of a class share the same Each object of the class gets its own copy
copy of Static data members. of Non-Static data members.

They can be accessed using the class They can be accessed only through an
name or object. object of the class.

(d) Write the difference between length and length().

Answer

length length()

length is an attribute i.e. a data member of array. length() is a member method of


String class.

It gives the length of an array i.e. the number of It gives the number of characters
elements stored in an array. present in a string.

(e) Differentiate between private and protected visibility modifiers.

Answer

Private members are only accessible inside the class in which they are defined and they
cannot be inherited by derived classes. Protected members are also only accessible
inside the class in which they are defined but they can be inherited by derived classes.

Question 3

(a) What do you understand by the term data abstraction? Explain with an example.

Answer

Data Abstraction refers to the act of representing essential features without including the
background details or explanations. A Switchboard is an example of Data Abstraction. It
hides all the details of the circuitry and current flow and provides a very simple way to
switch ON or OFF electrical appliances.

(b)(i) What will be the output of the following code?

int m = 2;
int n = 15;
for(int i = 1; i < 5; i++);
m++;
--n;
System.out.println("m = " + m);
System.out.println("n = " + n);

Answer

Output

3/20
m=6
n=14

Explanation
As there are no curly braces after the for loop so only the statement m++; is inside the
loop. Loop executes 4 times so m becomes 6. The next statement --n; is outside the loop
so it is executed only once and n becomes 14.

(b)(ii) What will be the output of the following code?

char x = 'A';
int m;
m = (x == 'a')? 'A' : 'a';
System.out.println("m = " + m);

Answer

Output

m = 97

Explanation
The condition x == 'a' is false as X has the value of 'A'. So, the ternary operator returns 'a'
that is assigned to m. But m is an int variable not a char variable. So, through implicit
conversion Java converts 'a' to its numeric ASCII value 97 and that gets assigned to m.

(c) Analyze the following program segment and determine how many times the
loop will be executed and what will be the output of the program segment.

int k = 1, i = 2;
while(++i < 6)
k *= i;
System.out.println(k);

Answer

Output

60

Explanation
This table shows the change in values of i and k as while loop iterates:

i k Remarks

2 1 Initial values

3 3 1st Iteration

4 12 2nd Iteration

5 60 3rd Iteration

4/20
i k Remarks

6 60 Once i becomes 6, condition is false and loop stops iterating.

Notice that System.out.println(k); is not inside while loop. As there are no curly
braces so only the statement k *= i; is inside the loop. The statement
System.out.println(k); is outside the while loop, it is executed once and prints value
of k which is 60 to the console.

(d) Give the prototype of a function check which receives a character ch and an
integer n and returns true or false.

Answer

boolean check(char ch, int n)

(e) State two features of a constructor.

Answer

1. A constructor has the same name as that of the class.


2. A constructor has no return type, not even void.

(f) Write a statement each to perform the following task on a string:

1. Extract the second-last character of a word stored in the variable wd.


2. Check if the second character of a string str is in uppercase.

Answer

1. char ch = wd.charAt(wd.length() - 2);


2. boolean res = Character.isUpperCase(str.charAt(1));

(g) What will the following function return when executed?

1. Math.max(-17, -19)
2. Math.ceil(7.8)

Answer

1. -17
2. 8.0

(h)(i) Why is an object called an instance of a class?

Answer

A class can create objects of itself with different characteristics and common behaviour.
So, we can say that an Object represents a specific state of the class. For these reasons,
an Object is called an Instance of a Class.

5/20
(h)(ii) What is the use of the keyword import?

Answer

import keyword is used to import built-in and user-defined packages into our Java
program.

Section B

Question 4

Write a program 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".

5, 7, 9, 11, 15, 20, 30, 45, 89, 97

Answer

import java.util.Scanner;

public class KboatBinarySearch


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


int arr[] = {5, 7, 9, 11, 15, 20, 30, 45, 89, 97};

System.out.print("Enter number to search: ");


int n = in.nextInt();

int l = 0, h = arr.length - 1, index = -1;


while (l <= h) {
int m = (l + h) / 2;
if (arr[m] < n)
l = m + 1;
else if (arr[m] > n)
h = m - 1;
else {
index = m;
break;
}

if (index == -1) {
System.out.println("Search element not found");
}
else {
System.out.println(n + " found at position " + index);
}
}
}

6/20
Output

Question 5

Define a class Student as given below:

Data members/instance variables:


name, age, m1, m2, m3 (marks in 3 subjects), maximum, average

Member methods:

1. A parameterized constructor to initialize the data members.


2. To accept the details of a student.
3. To compute the average and the maximum out of three marks.
4. To display the name, age, marks in three subjects, maximum and average.

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

Answer

8/20
import java.util.Scanner;

public class Student


{
private String name;
private int age;
private int m1;
private int m2;
private int m3;
private int maximum;
private double average;

public Student(String n, int a, int s1,


int s2, int s3) {
name = n;
age = a;
m1 = s1;
m2 = s2;
m3 = s3;
}

public Student() {
name = "";
age = 0;
m1 = 0;
m2 = 0;
m3 = 0;
maximum = 0;
average = 0;
}

public void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
name = in.nextLine();
System.out.print("Enter age: ");
age = in.nextInt();
System.out.print("Enter Subject 1 Marks: ");
m1 = in.nextInt();
System.out.print("Enter Subject 2 Marks: ");
m2 = in.nextInt();
System.out.print("Enter Subject 3 Marks: ");
m3 = in.nextInt();
}

public void compute() {


if (m1 > m2 && m1 > m3)
maximum = m1;
else if (m2 > m1 && m2 > m3)
maximum = m2;
else
maximum = m3;

average = (m1 + m2 + m3) / 3.0;


}

9/20
public void display() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Subject 1 Marks: " + m1);
System.out.println("Subject 2 Marks: " + m2);
System.out.println("Subject 3 Marks: " + m3);
System.out.println("Maximum Marks: " + maximum);
System.out.println("Average Marks: " + average);
}

public static void main(String args[]) {


Student obj = new Student();
obj.accept();
obj.compute();
obj.display();
}
}

Output

Question 6

10/20
Shasha Travels Pvt. Ltd. gives the following discount to its customers:

Ticket Amount Discount

Above Rs. 70000 18%

Rs. 55001 to Rs. 70000 16%

Rs. 35001 to Rs. 55000 12%

Rs. 25001 to Rs. 35000 10%

Less than Rs. 25001 2%

Write a program to input the name and ticket amount for the customer and calculate the
discount amount and net amount to be paid. Display the output in the following format for
each customer:

Sl. No. Name Ticket Charges Discount Net Amount

(Assume that there are 15 customers, first customer is given the serial no (SI. No.) 1, next
customer 2 …….. and so on)

Answer

11/20
import java.util.Scanner;

public class KboatShashaTravels


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String names[] = new String[15];
int amounts[] = new int[15];

for (int i = 0; i < 15; i++) {


System.out.print("Enter " + "Customer " + (i+1) + " Name: ");
names[i] = in.nextLine();
System.out.print("Enter " + "Customer " + (i+1) + " Ticket Charges:
");
amounts[i] = in.nextInt();
in.nextLine();
}

System.out.println("Sl. No.\tName\t\tTicket Charges\tDiscount\t\tNet


Amount");

for (int i = 0; i < 15; i++) {


int dp = 0;
int amt = amounts[i];
if (amt > 70000)
dp = 18;
else if (amt >= 55001)
dp = 16;
else if (amt >= 35001)
dp = 12;
else if (amt >= 25001)
dp = 10;
else
dp = 2;

double disc = amt * dp / 100.0;


double net = amt - disc;

System.out.println((i+1) + "\t" + names[i]


+ "\t" + amounts[i] + "\t\t"
+ disc + "\t\t" + net);
}
}
}

Output

12/20
Question 7

Write a menu driven program to accept a number from the user and check whether it is a
Prime number or an Automorphic number.

(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and itself)

Example: 3,5,7,11

(b) Automorphic number: (Automorphic number is the number which is contained in the
last digit(s) of its square.)

Example: 25 is an Automorphic number as its square is 625 and 25 is present as the last
two digits.

Answer

13/20
import java.util.Scanner;

public class KboatPrimeAutomorphic


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Prime number");
System.out.println("2. Automorphic number");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
System.out.print("Enter number: ");
int num = in.nextInt();

switch (choice) {
case 1:
int c = 0;
for (int i = 1; i <= num; i++) {
if (num % i == 0) {
c++;
}
}
if (c == 2)
System.out.println(num + " is Prime");
else
System.out.println(num + " is not Prime");
break;

case 2:
int numCopy = num;
int sq = num * num;
int d = 0;

/*
* Count the number of
* digits in num
*/
while(num > 0) {
d++;
num /= 10;
}

/*
* Extract the last d digits
* from square of num
*/
int ld = (int)(sq % Math.pow(10, d));

if (ld == numCopy)
System.out.println(numCopy + " is automorphic");
else
System.out.println(numCopy + " is not automorphic");
break;

default:
System.out.println("Incorrect Choice");
break;

14/20
}
}
}

Output

Question 8

Write a program to store 6 elements in an array P and 4 elements in an array Q. Now,


produce a third array R, containing all the elements of array P and Q. Display the
resultant array.

Input Input Output

P[ ] Q[ ] R[ ]

15/20
Input Input Output

4 19 4

6 23 6

1 7 1

2 8 2

3 3

10 10

19

23

Answer

16/20
import java.util.Scanner;

public class Kboat3Arrays


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int P[] = new int[6];


int Q[] = new int[4];
int R[] = new int[10];
int i = 0;

System.out.println("Enter 6 elements of array P:");


for (i = 0; i < P.length; i++) {
P[i] = in.nextInt();
}

System.out.println("Enter 4 elements of array Q:");


for (i = 0; i < Q.length; i++) {
Q[i] = in.nextInt();
}

i = 0;
while(i < P.length) {
R[i] = P[i];
i++;
}

int j = 0;
while(j < Q.length) {
R[i++] = Q[j++];
}

System.out.println("Elements of Array R:");


for (i = 0; i < R.length; i++) {
System.out.print(R[i] + " ");
}
}
}

Output

17/20
Question 9

Write a program to input a sentence. Count and display the frequency of each letter of the
sentence in alphabetical order.
Sample Input: COMPUTER APPLICATIONS
Sample Output:

Character Frequency Character Frequency

A 2 O 2

C 2 P 3

I 1 R 1

L 2 S 1

M 1 T 2

N 1 U 1

Answer

18/20
import java.util.Scanner;

public class KboatLetterFreq


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
str = str.toUpperCase();
int freqMap[] = new int[26];
int len = str.length();

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


char ch = str.charAt(i);
if (Character.isLetter(ch)) {
int chIdx = ch - 65;
freqMap[chIdx]++;
}
}

System.out.println("Character\tFrequency");
for (int i = 0; i < freqMap.length; i++) {
if (freqMap[i] > 0) {
System.out.println((char)(i + 65)
+ "\t\t" + freqMap[i]);
}
}
}
}

Output

19/20
20/20
Solved 2011 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/n65x7/year-2011

2011

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) What is the difference between an object and a class?

Answer

A class is a blue print that represents a set of objects that share common characteristics
and behaviour whereas an object is a specific instance of a class having a specific
identity, specific characteristics and specific behaviour.

(b) What does the token 'keyword' refer to in the context of Java? Give an example
for keyword.

Answer

Keywords are reserved words that have a special meaning for the Java compiler. Java
compiler reserves these words for its own use so Keywords cannot be used as identifiers.
An example of keyword is class.

(c) State the difference between entry controlled loop and exit controlled loop.

Answer

Entry controlled loop Exit controlled loop

It checks the condition at the time of It checks the condition after executing its body. If
entry. Only if the condition is true, the condition is true, loop will perform the next
the program control enters the body iteration otherwise program control will move out
of the loop. of the loop.

Loop does not execute at all if the The loop executes at least once even if the
condition is false. condition is false.

Example: for and while loops Example: do-while loop

(d) What are the two ways of invoking functions?

1/18
Answer

Two ways of invoking functions are:

1. Pass by value.
2. Pass by reference.

(e) What is the difference between / and % operators?

Answer

/ %

Division operator Modulus operator

Returns the quotient of division operation Returns the remainder of division operation

Example: int a = 5 / 2; Here a will get the Example: int b = 5 % 2; Here b will get the
value of 2 which is the quotient of this value of 1 which is the remainder of this
division operation division operation

Question 2

(a) State the total size in bytes, of the arrays a[4] of char data type and p[4] of float
data type.

Answer

Size of char a[4] is 4 × 2 = 8 Bytes.


Size of float p[4] is 4 × 4 = 16 Bytes.

(b) (i) Name the package that contains Scanner class.


(ii) Which unit of the class gets called, when the object of the class is created?

Answer

(i) java.util
(ii) Constructor

(c) Give the output of the following:

String n = "Computer Knowledge";


String m = "Computer Applications";
System.out.println(n.substring(0, 8).concat(m.substring(9)));
System.out.println(n.endsWith("e"));

Answer

Output

ComputerApplications
true

2/18
Explanation
n.substring(0,8) returns the substring of n starting at index 0 till 7 (i.e. 8 - 1 = 7) which is
"Computer". m.substring(9) returns the substring of m starting at index 9 till the end of the
string which is "Applications". concat() method joins "Computer" and "Applications"
together to give the output as ComputerApplications.

(d) Write the output of the following:

1. System.out.println(Character.isUpperCase('R'));
2. System.out.println(Character.toUpperCase('j'));

Answer

1. true
2. J

(e) What is the role of keyword void in declaring functions?

Answer

The keyword 'void' signifies that the function doesn't return a value to the calling function.

Question 3

(a) Analyze the following program segment and determine how many times the
loop will be executed and what will be the output of the program segment?

int p = 200;
while(true){
if(p < 100)
break;
p = p - 20;
}
System.out.println(p);

Answer

Output

80

The loop executes 6 times

Explanation

p Remarks

200 Initial Value

180 1st Iteration

160 2nd Iteration

3/18
p Remarks

140 3rd Iteration

120 4th Iteration

100 5th Iteration

80 6th Iteration. Now p < 100 becomes true so break statement is executed
terminating the loop.

(b) What will be the output of the following code?

(i)

int k = 5, j = 9;
k += k++ - ++j + k;
System.out.println("k = " + k);
System.out.println("j = " + j);

(ii)

double b = -15.6;
double a = Math.rint(Math.abs(b));
System.out.println("a = " + a);

Answer

(i)

Output

k = 6
j = 10

Explanation
k += k++ - ++j + k
⇒ k = 5 + (5 - 10 + 6)
⇒k=5+1
⇒k=6

++j increments j to 10

(ii)

Output

16.0

Explanation
Math.abs(-15.6) gives 15.6. Math.rint(15.6) gives 16.0.

(c) Explain the concept of constructor overloading with an example.

4/18
Answer

Constructor overloading is a technique in Java through which a class can have more than
one constructor with different parameter lists. The different constructors of the class are
differentiated by the compiler using the number of parameters in the list and their types.
For example, the Rectangle class below has two constructors:

class Rectangle {
int length;
int breadth;

//Constructor 1
public Rectangle() {
length = 0;
breadth = 0;
}

//Constructor 2
public Rectangle(int l, int b) {
length = l;
breadth = b;
}

public static void main(String[] args) {


//Constructor 1 called
Rectangle obj1 = new Rectangle();

//Constructor 2 called
Rectangle obj2 = new Rectangle(10, 15);
}
}

(d) Give the prototype of a function search which receives a sentence 'sent' and
word 'w' and returns 1 or 0.

Answer

int search(String sent, String w)

(e) Write an expression in Java for:

z=x+y5x3+2y​

Answer

z = (5 * x * x * x + 2 * y) / (x + y)

(f) Write a statement each to perform the following tasks on a string:

1. Find and display the position of the last space in a string s.


2. Convert a number stored in a string variable x to double data type.

Answer

5/18
1. System.out.println(s.lastIndexOf(" "));
2. double num = Double.parseDouble(x);

(g) Name the keyword that:

1. informs that an error has occurred in an input/output operation.


2. distinguishes between instance variable and class variable.

Answer

1. throws IOException
2. static

(h) What are library classes? Give an example.

Answer

Java Library classes are a set of predefined classes in the form of packages that are
provided to the programmer as part of Java installation. Library classes simplify the job of
programmers by providing built-in methods for common and non-trivial tasks like taking
input from user, displaying output to user, etc. For example, System class in java.lang
package of Java Library classes provides the print() and println() methods for displaying
output to user.

(i) Write one difference between Linear Search and Binary Search.

Answer

Linear search works on unsorted as well as sorted arrays whereas Binary search works
on only sorted arrays.

Section B

Question 4

Define a class called 'Mobike' with the following specifications:

Data Members Purpose

int bno To store the bike number

int phno To store the phone number of the customer

String name To store the name of the customer

int days To store the number of days the bike is taken on rent

int charge To calculate and store the rental charge

Member Methods Purpose

6/18
Member Methods Purpose

void input() To input and store the details of the customer

void compute() To compute the rental charge

void display() To display the details in the given format

The rent for a mobike is charged on the following basis:

Days Charge

For first five days ₹500 per day

For next five days ₹400 per day

Rest of the days ₹200 per day

Output:

Bike No. Phone No. Name No. of days Charge


xxxxxxx xxxxxxxx xxxx xxx xxxxxx

Answer

7/18
import java.util.Scanner;

public class Mobike


{
private int bno;
private int phno;
private int days;
private int charge;
private String name;

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Customer Name: ");
name = in.nextLine();
System.out.print("Enter Customer Phone Number: ");
phno = in.nextInt();
System.out.print("Enter Bike Number: ");
bno = in.nextInt();
System.out.print("Enter Number of Days: ");
days = in.nextInt();
}

public void compute() {


if (days <= 5)
charge = days * 500;
else if (days <= 10)
charge = (5 * 500) + ((days - 5) * 400);
else
charge = (5 * 500) + (5 * 400) + ((days - 10) * 200);
}

public void display() {


System.out.println("Bike No.\tPhone No.\tName\tNo. of days \tCharge");
System.out.println(bno + "\t" + phno + "\t" + name + "\t" + days
+ "\t" + charge);
}

public static void main(String args[]) {


Mobike obj = new Mobike();
obj.input();
obj.compute();
obj.display();
}
}

Output

8/18
Question 5

Write a program to input and sort the weight of ten people. Sort and display them in
descending order using the selection sort technique.

Answer

9/18
import java.util.Scanner;

public class KboatSelectionSort


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
double weightArr[] = new double[10];
System.out.println("Enter weights of 10 people: ");
for (int i = 0; i < 10; i++) {
weightArr[i] = in.nextDouble();
}

for (int i = 0; i < 9; i++) {


int idx = i;
for (int j = i + 1; j < 10; j++) {
if (weightArr[j] > weightArr[idx])
idx = j;
}

double t = weightArr[i];
weightArr[i] = weightArr[idx];
weightArr[idx] = t;
}

System.out.println("Sorted Weights Array:");


for (int i = 0; i < 10; i++) {
System.out.print(weightArr[i] + " ");
}
}
}

Output

Question 6

10/18
Write a program to input a number and print whether the number is a special number or
not.

(A number is said to be a special number, if the sum of the factorial of the digits of the
number is same as the original number).

Example:
145 is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.
(Where ! stands for factorial of the number and the factorial value of a number is the
product of all integers from 1 to that number, example 5! = 1 * 2 * 3 * 4 * 5 = 120)

Answer

import java.util.Scanner;

public class KboatSpecialNum


{
public static int fact(int y) {
int f = 1;
for (int i = 1; i <= y; i++) {
f *= i;
}
return f;
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int num = in.nextInt();

int t = num;
int sum = 0;
while (t != 0) {
int d = t % 10;
sum += fact(d);
t /= 10;
}

if (sum == num)
System.out.println(num + " is a special number");
else
System.out.println(num + " is not a special number");

}
}

Output

11/18
Question 7

Write a program to accept a word and convert it into lower case, if it is in upper case.
Display the new word by replacing only the vowels with the letter following it.
Sample Input: computer
Sample Output: cpmpvtfr

Answer

12/18
import java.util.Scanner;

public class KboatVowelReplace


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();

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


char ch = str.charAt(i);

if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {

char nextChar = (char)(ch + 1);


newStr = newStr + nextChar;

}
else {
newStr = newStr + ch;
}
}

System.out.println(newStr);
}
}

Output

13/18
Question 8

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

1. void compare(int, int) — to compare two integers values and print the greater of the
two integers.
2. void compare(char, char) — to compare the numeric value of two characters and
print with the higher numeric value.
3. void compare(String, String) — to compare the length of the two strings and print
the longer of the two.

Answer

14/18
import java.util.Scanner;

public class KboatCompare


{
public void compare(int a, int b) {

if (a > b) {
System.out.println(a);
}
else {
System.out.println(b);
}

public void compare(char a, char b) {


int x = (int)a;
int y = (int)b;

if (x > y) {
System.out.println(a);
}
else {
System.out.println(b);
}

public void compare(String a, String b) {

int l1 = a.length();
int l2 = b.length();

if (l1 > l2) {


System.out.println(a);
}
else {
System.out.println(b);
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
KboatCompare obj = new KboatCompare();

System.out.print("Enter first integer: ");


int n1 = in.nextInt();
System.out.print("Enter second integer: ");
int n2 = in.nextInt();
obj.compare(n1, n2);

System.out.print("Enter first character: ");


char c1 = in.next().charAt(0);
System.out.print("Enter second character: ");
char c2 = in.next().charAt(0);

15/18
in.nextLine();
obj.compare(c1, c2);

System.out.print("Enter first string: ");


String s1 = in.nextLine();
System.out.print("Enter second string: ");
String s2 = in.nextLine();
obj.compare(s1, s2);
}
}

Output

Question 9

Write a menu driven program to perform the following tasks by using Switch case
statement:

(a) To print the series:


0, 3, 8, 15, 24, ............ to n terms. (value of 'n' is to be an input by the user)

(b) To find the sum of the series:


S = (1/2) + (3/4) + (5/6) + (7/8) + ........... + (19/20)

Answer

16/18
import java.util.Scanner;

public class KboatSeriesMenu


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 to print series");
System.out.println("0, 3, 8, 15, 24,....to n terms");
System.out.println();
System.out.println("Type 2 to find sum of series");
System.out.println("(1/2) + (3/4) + (5/6) + (7/8) +....+ (19/20)");
System.out.println();
System.out.print("Enter your choice: ");
int choice = in.nextInt();

switch (choice) {
case 1:
System.out.print("Enter n: ");
int n = in.nextInt();
for (int i = 1; i <= n; i++)
System.out.print(((i * i) - 1) + " ");
System.out.println();
break;

case 2:
double sum = 0;
for (int i = 1; i <= 19; i = i + 2)
sum += i / (double)(i + 1);
System.out.println("Sum = " + sum);
break;

default:
System.out.println("Incorrect Choice");
break;
}
}
}

Output

17/18
18/18
Solved 2012 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/n0oZm/year-
2012

2012

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) Give one example each of a primitive data type and a composite data type.

Answer

1. int
2. array

(b) Give one point of difference between unary and binary operators.

Answer

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

(c) Differentiate between call by value or pass by value and call by reference or
pass by reference.

Answer

Call by value Call by reference

Values of actual parameters are copied to Reference of actual parameters is


formal parameters. passed to formal parameters.

Changes made to formal parameters are Changes made to formal parameters are
not reflected back to actual parameters. reflected back to actual parameters.

(d) Write a Java expression for:

2as+u2 ​

Answer

Math.sqrt(2 * a * s + u * u)

1/17
(e) Name the type of error (syntax, runtime or logical error) in each case given
below:

1. Division by a variable that contains a value of zero.


2. Multiplication operator used when the operation should be division.
3. Missing semicolon.

Answer

1. Runtime error
2. Logical error
3. syntax error

Question 2

(a) Create a class with one integer instance variable. Initialize the variable using:

1. default constructor
2. parameterized constructor

Answer

class Number {
int a;

public Number() {
a = 0;
}

public Number(int x) {
a = x;
}
}

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

Scanner sc = ____ Scanner(__________);

Answer

Scanner sc = new Scanner(System.in);

(c) What is an array? Write a statement to declare an integer array of 10 elements.

Answer

An array is a structure to store a number of values of the same data type in contiguous
memory locations. The following statement declares an integer array of 10 elements:

int arr[] = new int[10];

(d) Name the search or sort algorithm that:

2/17
1. 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.
2. At each stage, compares the sought key value with the key value of the
middle element of the array.

Answer

1. Selection Sort
2. Binary Search

(e) Differentiate between public and private modifiers for members of a class.

Answer

public modifier makes the class members accessible both within and outside their class
whereas private modifier makes the class members accessible only within the class in
which they are declared.

Question 3

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

int a = 63, b = 36;


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

Answer

Output

x = true
y = 36

Explanation
The ternary operator (a > b)? true : false returns true as its condition a > b is true so
it returns its first expression that is true.

The ternary operator (a < b)? a : b returns b as its condition a < b is false so it returns
its second expression that is b. Value of b is 36 so y also becomes 36.

(b) State the values of n and ch.

char c = 'A';
int n = c + 1;
char ch = (char)n;

Answer

Value of n is 66 and ch is B.

int n = c + 1, here due to implicit conversion, 'A' will be converted to its ASCII value 65. 1
is added to it making the value of n 66.

3/17
char ch = (char)n, here through explicit conversion 66 is converted to its corresponding
character that is 'B' so value of ch becomes B.

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

int x = 4;
x += (x++) + (++x) + x;

Answer

x += (x++) + (++x) + x
⇒ x = x + ((x++) + (++x) + x)
⇒ x = 4 + (4 + 6 + 6)
⇒ x = 4 + 16
⇒ x = 20

(d) Give output of the following program segment:

double x = 2.9, y = 2.5;


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

Answer

Output

2.0
3.0

Explanation
Math.floor(2.9) gives 2.0. Math.min(2.0, 2.5) gives 2.0.

Math.ceil(2.9) gives 3.0. Math.max(3.0, 2.5) gives 3.0.

(e) State the output of the following program segment:

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

Answer

Output

false
true

Explanation
Putting the value of n in s.substring(5, n), it becomes s.substring(5, 11). This gives
"nation". As s does not start with "nation" so s.startsWith(s.substring(5, n)) returns false.

s.charAt(2) is a and s.charAt(6) is also a so both are equal

4/17
(f) State the method that:

1. Converts a string to a primitive float data type.


2. Determines if the specified character is an uppercase character.

Answer

1. Float.parseFloat()
2. Character.isUpperCase()

(g) State the data type and values of a and b after the following segment is
executed:

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


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

Answer

Data type of a is int and value is 2. Data type of b is boolean and value is false.

(h) What will the following code output:

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

Answer

Output

0
8

Explanation
The first m appears at index 0 and the last m appears at index 8.

(i) Rewrite the following program segment using while instead of for statement.

int f = 1, i;
for(i = 1; i <= 5; i++){
f *= i;
System.out.println(f);
}

Answer

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

5/17
(j) In the program given below, state the name and the value of the:

1. method argument or argument variable


2. class variable
3. local variable
4. instance variable

class MyClass{
static int x = 7;
int y = 2;
public static void main(String args[]){
MyClass obj = new MyClass();
System.out.println(x);
obj.sampleMethod(5);
int a = 6;
System.out.println(a);
}
void sampleMethod(int n){
System.out.println(n);
System.out.println(y);
}
}

Answer

1. Method argument/Argument variable is n


2. Class variable is x
3. Local variable is a
4. Instance variable is y

Section B

Question 4

Define a class called Library with the following description:

Instance Variables/Data Members:


int accNum — stores the accession number of the book.
String title — stores the title of the book.
String author — stores the name of the author.

Member methods:

1. void input() — To input and store the accession number, title and author.
2. void compute() — To accept the number of days late, calculate and display the fine
charged at the rate of Rs. 2 per day.
3. void display() — To display the details in the following format:

Accession Number Title Author

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

Answer

import java.util.Scanner;

public class Library


{
private int accNum;
private String title;
private String author;

void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter book title: ");
title = in.nextLine();
System.out.print("Enter author: ");
author = in.nextLine();
System.out.print("Enter accession number: ");
accNum = in.nextInt();
}

void compute() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of days late: ");
int days = in.nextInt();
int fine = days * 2;
System.out.println("Fine = Rs." + fine);
}

void display() {
System.out.println("Accession Number\tTitle\tAuthor");
System.out.println(accNum + "\t\t" + title + "\t" + author);
}

public static void main(String args[]) {


Library obj = new Library();
obj.input();
obj.display();
obj.compute();
}
}

Output

7/17
Question 5

Given below is a hypothetical table showing rates of income tax for male citizens below
the age of 65 years:

Taxable income (TI) in ₹ Income Tax in ₹

Does not exceed Rs. 1,60,000 Nil

Is greater than Rs. 1,60,000 and less than or equal to Rs. (TI - 1,60,000) x 10%
5,00,000.

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

Is greater than Rs. 8,00,000 [(TI - 8,00,000) x 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 years or the gender is female, display “wrong category”. If the
age is less than or equal to 65 years and the gender is male, compute and display the
income tax payable as per the table given above.

Answer

8/17
import java.util.Scanner;

public class KboatIncomeTax


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Gender(male/female): ");
String gender = in.nextLine();
System.out.print("Enter Age: ");
int age = in.nextInt();
System.out.print("Enter Taxable Income: ");
double ti = in.nextDouble();
double tax = 0.0;

if (age > 65 || gender.equalsIgnoreCase("female")) {


System.out.print("Wrong Category");
}
else {
if (ti <= 160000)
tax = 0;
else if (ti <= 500000)
tax = (ti - 160000) * 10 / 100;
else if (ti <= 800000)
tax = 34000 + ((ti - 500000) * 20 / 100);
else
tax = 94000 + ((ti - 800000) * 30 / 100);

System.out.println("Tax Payable: " + tax);


}
}
}

Output

9/17
Question 6

Write a program to accept a string. Convert the string into upper case letters. 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

Answer

import java.util.Scanner;

public class KboatLetterSeq


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String s = in.nextLine();
String str = s.toUpperCase();
int count = 0;
int len = str.length();

for (int i = 0; i < len - 1; i++) {


if (str.charAt(i) == str.charAt(i + 1))
count++;
}

System.out.println("Double Letter Sequence Count = " + count);

}
}

Output

10/17
Question 7

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

1. void polygon(int n, char ch) — with one integer and one character type argument to
draw a filled square of side n using the character stored in ch.
2. void polygon(int x, int y) — with two integer arguments that draws a filled rectangle
of length x and breadth y, using the symbol '@'.
3. void polygon() — with no argument that draws a filled triangle shown below:

Example:

1. Input value of n=2, ch = 'O'


Output:
OO
OO
2. Input value of x = 2, y = 5
Output:
@@@@@
@@@@@
3. Output:
*
**
***

Answer

11/17
public class KboatPolygon
{
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}

public void polygon(int x, int y) {


for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
System.out.print('@');
}
System.out.println();
}
}

public void polygon() {


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}

public static void main(String args[]) {


KboatPolygon obj = new KboatPolygon();
obj.polygon(2, 'o');
System.out.println();
obj.polygon(2, 5);
System.out.println();
obj.polygon();
}
}

Output

12/17
Question 8

Using a switch statement, write a menu driven program to:


(a) 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 previous two.
(b) 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 displayed.

Answer

13/17
import java.util.Scanner;

public class KboatFibonacciNDigitSum


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Fibonacci Series");
System.out.println("2. Sum of digits");
System.out.print("Enter your choice: ");
int ch = in.nextInt();

switch (ch) {
case 1:
int a = 0, b = 1;
System.out.print(a + " " + b);
for (int i = 3; i <= 10; i++) {
int term = a + b;
System.out.print(" " + term);
a = b;
b = term;
}
break;

case 2:
System.out.print("Enter number: ");
int num = in.nextInt();
int sum = 0;
while (num != 0) {
sum += num % 10;
num /= 10;
}
System.out.println("Sum of Digits " + " = " + sum);
break;

default:
System.out.println("Incorrect choice");
break;
}
}
}

Output

14/17
Question 9

Write a program to accept the names of 10 cities in a single dimensional string array and
their STD (Subscribers Trunk Dialling) codes in another single dimension integer array.
Search for the 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".

Answer

15/17
import java.util.Scanner;

public class KboatStdCodes


{
public static void main(String args[]) {
final int SIZE = 10;
Scanner in = new Scanner(System.in);
String cities[] = new String[SIZE];
String stdCodes[] = new String[SIZE];
System.out.println("Enter " + SIZE +
" cities and their STD codes:");

for (int i = 0; i < SIZE; i++) {


System.out.print("Enter City Name: ");
cities[i] = in.nextLine();
System.out.print("Enter its STD Code: ");
stdCodes[i] = in.nextLine();
}

System.out.print("Enter name of city to search: ");


String city = in.nextLine();

int idx;
for (idx = 0; idx < SIZE; idx++) {
if (city.compareToIgnoreCase(cities[idx]) == 0) {
break;
}
}

if (idx < SIZE) {


System.out.println("Search Successful");
System.out.println("City: " + cities[idx]);
System.out.println("STD Code: " + stdCodes[idx]);
}
else {
System.out.println("Search Unsuccessful");
}
}
}

Output

16/17
17/17
Solved 2013 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/nRm4n/year-
2013

2013

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) What is meant by precedence of operators?

Answer

Precedence of operators refers to the order in which the operators are applied to the
operands in an expression.

(b) What is a literal?

Answer

Literals are data items that are fixed data values. Java provides different types of literals
like:

1. Integer Literals
2. Floating-Point Literals
3. Boolean Literals
4. Character Literals
5. String Literals
6. null Literal

(c) State the Java concept that is implemented through:

1. a superclass and a subclass.


2. the act of representing essential features without including background
details.

Answer

1. Inheritance
2. Abstraction

(d) Give a difference between a constructor and a method.

1/18
Answer

Constructor has the same name as class name whereas function should have a different
name than class name.

(e) What are the types of casting shown by the following examples?

1. double x = 15.2;
int y = (int) x;

2. int x = 12;
long y = x;

Answer

1. Explicit Type Casting


2. Implicit Type Casting

Question 2

(a) Name any two wrapper classes.

Answer

Two wrapper classes are:

1. Integer
2. Character

(b) What is the difference between a break statement and a continue statement
when they occur in a loop?

Answer

When the break statement gets executed, it terminates its loop completely and control
reaches to the statement immediately following the loop. The continue statement
terminates only the current iteration of the loop by skipping rest of the statements in the
body of the loop.

(c) Write statements to show how finding the length of a character array char[]
differs from finding the length of a String object str.

Answer

Java code snippet to find length of character array:

char ch[] = {'x', 'y', 'z'};


int len = ch.length

Java code snippet to find length of String object str:

2/18
String str = "Test";
int len = str.length();

(d) Name the Java keyword that:

1. indicates that a method has no return type.


2. stores the address of the currently-calling object.

Answer

1. void
2. this

(e) What is an exception?

Answer

An exception is an abnormal condition that arises in a code sequence at run time.


Exceptions indicate to a calling method that an abnormal condition has occurred.

Question 3

(a) Write a Java statement to create an object mp4 of class Digital.

Answer

Digital MP4 = new Digital();

(b) State the values stored in the variables str1 and str2:

String s1 = "good";
String s2 = "world matters";
String str1 = s2.substring(5).replace('t', 'n');
String str2 = s1.concat(str1);

Answer

Value stored in str1 is " manners" and str2 is "good manners". (Note that str1 begins with
a space.)

Explanation
s2.substring(5) gives a substring from index 5 till the end of the string which is " matters".
The replace method replaces all 't' in " matters" with 'n' giving " manners". s1.concat(str1)
joins together "good" and " manners" so "good manners" is stored in str2.

(c) What does a class encapsulate?

Answer

A class encapsulates data and behavior.

(d) Rewrite the following program segment using the if..else statement:

3/18
comm = (sale > 15000)? sale * 5 / 100 : 0;

Answer

if(sale > 15000)


comm = sale * 5 / 100;
else
comm = 0;

(e) How many times will the following loop execute? What value will be returned?

int x = 2, y = 50;
do{
++x;
y -= x++;
}while(x <= 10);
return y;

Answer

The loop will run 5 times and the value returned is 15.

(f) What is the data type that the following library functions return?

1. isWhitespace(char ch)
2. Math.random()

Answer

1. boolean
2. double

(g) Write a Java expression for:

ut+21​ft2

Answer

u * t + 1 / 2.0 * f * t * t

(h) If int n[] = {1, 2, 3, 5, 7, 9, 13, 16}, what are the values of x and y?

x = Math.pow(n[4], n[2]);
y = Math.sqrt(n[5] + n[7]);

Answer

x = Math.pow(n[4], n[2]);
⇒ x = Math.pow(7, 3);
⇒ x = 343.0;

4/18
y = Math.sqrt(n[5] + n[7]);
⇒ y = Math.sqrt(9 + 16);
⇒ y = Math.sqrt(25);
⇒ y = 5.0;

(i) What is the final value of ctr when the iteration process given below, executes?

int ctr = 0;
for(int i = 1; i <= 5; i++)
for(int j = 1; j <= 5; j += 2)
++ctr;

Answer

The final value of ctr is 15.

The outer loop executes 5 times. For each iteration of outer loop, the inner loop executes
3 times. So the statement ++ctr; is executed a total of 5 x 3 = 15 times.

(j) Name the method of Scanner class that:

1. is used to input an integer data from the standard input stream.


2. is used to input a String data from the standard input stream.

Answer

1. nextInt()
2. nextLine()

Section B

Question 4

Define a class named FruitJuice with the following description:

Data Members Purpose

int product_code stores the product code number

String flavour stores the flavour of the juice (e.g., orange, apple, etc.)

String pack_type stores the type of packaging (e.g., tera-pack, PET bottle, etc.)

int pack_size stores package size (e.g., 200 mL, 400 mL, etc.)

int product_price stores the price of the product

Member
Methods Purpose

5/18
Member
Methods Purpose

FruitJuice() constructor to initialize integer data members to 0 and string data


members to ""

void input() to input and store the product code, flavour, pack type, pack size and
product price

void discount() to reduce the product price by 10

void display() to display the product code, flavour, pack type, pack size and product
price

Answer

6/18
import java.util.Scanner;

public class FruitJuice


{
private int product_code;
private String flavour;
private String pack_type;
private int pack_size;
private int product_price;

public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Flavour: ");
flavour = in.nextLine();
System.out.print("Enter Pack Type: ");
pack_type = in.nextLine();
System.out.print("Enter Product Code: ");
product_code = in.nextInt();
System.out.print("Enter Pack Size: ");
pack_size = in.nextInt();
System.out.print("Enter Product Price: ");
product_price = in.nextInt();
}

public void discount() {


product_price -= 10;
}

public void display() {


System.out.println("Product Code: " + product_code);
System.out.println("Flavour: " + flavour);
System.out.println("Pack Type: " + pack_type);
System.out.println("Pack Size: " + pack_size);
System.out.println("Product Price: " + product_price);
}

public static void main(String args[]) {


FruitJuice obj = new FruitJuice();
obj.input();
obj.discount();
obj.display();
}
}

Output

7/18
Question 5

The International Standard Book Number (ISBN) is a unique numeric book identifier
which is printed on every book. The ISBN is based upon a 10-digit code.

The ISBN is legal if:


1 × digit1 + 2 × digit2 + 3 × digit3 + 4 × digit4 + 5 × digit5 + 6 × digit6 + 7 × digit7 + 8 ×
digit8 + 9 × digit9 + 10 × digit10 is divisible by 11.

Example:
For an ISBN 1401601499
Sum = 1 × 1 + 2 × 4 + 3 × 0 + 4 × 1 + 5 × 6 + 6 × 0 + 7 × 1 + 8 × 4 + 9 × 9 + 10 × 9 = 253
which is divisible by 11.

Write a program to:

1. Input the ISBN code as a 10-digit integer.


2. If the ISBN is not a 10-digit integer, output the message "Illegal ISBN" and terminate
the program.
3. If the number is divisible by 11, output the message "Legal ISBN". If the sum is not
divisible by 11, output the message "Illegal ISBN".

Answer

8/18
import java.util.Scanner;

public class KboatISBNCheck


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the ISBN: ");
long isbn = in.nextLong();

int sum = 0, count = 0, m = 10;


while (isbn != 0) {
int d = (int)(isbn % 10);
count++;
sum += d * m;
m--;
isbn /= 10;
}

if (count != 10) {
System.out.println("Illegal ISBN");
}
else if (sum % 11 == 0) {
System.out.println("Legal ISBN");
}
else {
System.out.println("Illegal ISBN");
}
}
}

Output

9/18
Question 6

Write a program that encodes a word into Piglatin. To translate word into Piglatin word,
convert the word into uppercase and then place the first vowel of the original word as the
start of the new word along with the remaining alphabets. The alphabets present before
the vowel being shifted towards the end followed by "AY".

Sample Input 1: London


Output: ONDONLAY

Sample Input 2: Olympics


Output: OLYMPICSAY

Answer

10/18
import java.util.Scanner;

public class KboatPigLatin


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter word: ");
String word = in.next();
int len = word.length();

word=word.toUpperCase();
String piglatin="";
int flag=0;

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


{
char x = word.charAt(i);
if(x=='A' || x=='E' || x=='I' || x=='O' || x=='U')
{
piglatin=word.substring(i) + word.substring(0,i) + "AY";
flag=1;
break;
}
}

if(flag == 0)
{
piglatin = word + "AY";
}
System.out.println(word + " in Piglatin format is " + piglatin);
}
}

Output

11/18
Question 7

Write a program to input 10 integer elements in an array and sort them in descending
order using bubble sort technique.

Answer

12/18
import java.util.Scanner;

public class KboatBubbleSortDsc


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = 10;
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

13/18
Question 8

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

1. double series(double n) with one double argument and returns the sum of the
series.
sum = (1/1) + (1/2) + (1/3) + .......... + (1/n)
2. double series(double a, double n) with two double arguments and returns the sum
of the series.
sum = (1/a2) + (4/a5) + (7/a8) + (10/a11) + .......... to n terms

Answer

14/18
public class KboatSeries
{
double series(double n) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double term = 1.0 / i;
sum += term;
}
return sum;
}

double series(double a, double n) {


double sum = 0;
int x = 1;
for (int i = 1; i <= n; i++) {
int e = x + 1;
double term = x / Math.pow(a, e);
sum += term;
x += 3;
}
return sum;
}

public static void main(String args[]) {


KboatSeries obj = new KboatSeries();
System.out.println("First series sum = " + obj.series(5));
System.out.println("Second series sum = " + obj.series(3, 8));
}
}

Output

Question 9

Using the switch statement, write a menu driven program:

15/18
1. To check and display whether a number input by the user is a composite number or
not.
A number is said to be composite, if it has one or more than one factors excluding 1
and the number itself.
Example: 4, 6, 8, 9...
2. To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: Smallest digit is 2

For an incorrect choice, an appropriate error message should be displayed.

Answer

16/18
import java.util.Scanner;

public class KboatNumber


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Composite Number");
System.out.println("Type 2 for Smallest Digit");
System.out.print("Enter your choice: ");
int ch = in.nextInt();

switch (ch) {
case 1:
System.out.print("Enter Number: ");
int n = in.nextInt();
int c = 0;
for (int i = 1; i <= n; i++) {
if (n % i == 0)
c++;
}

if (c > 2)
System.out.println("Composite Number");
else
System.out.println("Not a Composite Number");
break;

case 2:
System.out.print("Enter Number: ");
int num = in.nextInt();
int s = 10;
while (num != 0) {
int d = num % 10;
if (d < s)
s = d;
num /= 10;
}
System.out.println("Smallest digit is " + s);
break;

default:
System.out.println("Wrong choice");
}
}
}

Output

17/18
18/18
Solved 2014 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/nq88K/year-2014

2014

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) Which of the following are valid comments ?

1. /*comment*/
2. /*comment
3. //comment
4. */comment*/

Answer

The valid comments are:

Option 1 — /*comment*/
Option 3 — //comment

(b) What is meant by a package ? Name any two java Application Programming
Interface packages.

Answer

A package is a named collection of Java classes that are grouped on the basis of their
functionality. Two java Application Programming Interface packages are:

1. java.util
2. java.io

(c) Name the primitive data type in Java that is:

1. a 64-bit integer and is used when you need a range of values wider than those
provided by int.
2. a single 16-bit Unicode character whose default value is '\u0000'.

Answer

1. long

1/17
2. char

(d) State one difference between the floating point literals float and double.

Answer

float literals double literals

float literals have a size of 32 bits so they double literals have a size of 64 bits so
can store a fractional number with around they can store a fractional number with
6-7 total digits of precision. 15-16 total digits of precision.

(e) Find the errors in the given program segment and re-write the statements
correctly to assign values to an integer array.

int a = new int (5);


for (int i=0; i<=5; i++) a[i]=i;

Answer

Corrected Code:

int a[] = new int[5];


for (int i = 0; i < 5; i++)
a[i] = i;

Question 2

(a) Operators with higher precedence are evaluated before operators with relatively
lower precedence. Arrange the operators given below in order of higher
precedence to lower precedence:

1. &&
2. %
3. >=
4. ++

Answer

++
%
>=
&&

(b) Identify the statements listed below as assignment, increment, method


invocation or object creation statements.

1. System.out.println("Java");
2. costPrice = 457.50;
3. Car hybrid = new Car();

2/17
4. petrolPrice++;

Answer

1. Method Invocation
2. Assignment
3. Object Creation
4. Increment

(c) Give two differences between the switch statement and the if-else statement

Answer

switch if-else

switch can only test if the if-else can test for any boolean expression like
expression is equal to any of its less than, greater than, equal to, not equal to,
case constants etc.

It is a multiple branching flow of It is a bi-directional flow of control statement


control statement

(d) What is an infinite loop? Write an infinite loop statement.

Answer

A loop which continues iterating indefinitely and never stops is termed as infinite loop.
Below is an example of infinite loop:

for (;;)
System.out.println("Infinite Loop");

(e) What is constructor? When is it invoked?

Answer

A constructor is a member method that is written with the same name as the class name
and is used to initialize the data members or instance variables. A constructor does not
have a return type. It is invoked at the time of creating any object of the class.

Question 3

(a) List the variables from those given below that are composite data types:

1. static int x;
2. arr[i]=10;
3. obj.display();
4. boolean b;
5. private char chr;
6. String str;

3/17
Answer

The composite data types are:

arr[i]=10;
obj.display();
String str;

(b) State the output of the following program segment:

String str1 = "great"; String str2 = "minds";


System.out.println(str1.substring(0,2).concat(str2.substring(1)));
System.out.println(("WH" + (str1.substring(2).toUpperCase())));

Answer

The output of the above code is:

grinds
WHEAT

Explanation:

1. str1.substring(0,2) returns "gr". str2.substring(1) returns "inds". Due to concat both


are joined together to give the output as "grinds".
2. str1.substring(2) returns "eat". It is converted to uppercase and joined to "WH" to
give the output as "WHEAT".

(c) What are the final values stored in variable x and y below?

double a = -6.35;
double b = 14.74;
double x = Math.abs(Math.ceil(a));
double y = Math.rint(Math.max(a,b));

Answer

The final value stored in variable x is 6.0 and y is 15.0.

Explanation:

1. Math.ceil(a) gives -6.0 and Math.abs(-6.0) is 6.0.


2. Math.max(a,b) gives 14.74 and Math.rint(14.74) gives 15.0.

(d) Rewrite the following program segment using if-else statements instead of the
ternary operator:

String grade = (marks>=90)?"A": (marks>=80)? "B": "C";

Answer

4/17
String grade;
if (marks >= 90)
grade = "A";
else if (marks >= 80)
grade = "B";
else
grade = "C";

(e) Give the output of the following method:

public static void main (String [] args){


int a = 5;
a++;
System.out.println(a);
a -= (a--) - (--a);
System.out.println(a);}

Answer

Output

6
4

Explanation
1. a++ increments value of a by 1 so a becomes 6.
2. a -= (a--) - (--a)
⇒ a = a - ((a--) - (--a))
⇒ a = 6 - (6 - 4)
⇒a=6-2
⇒a=4

(f) What is the data type returned by the library functions :

1. compareTo()
2. equals()

Answer

1. int
2. boolean

(g) State the value of characteristic and mantissa when the following code is
executed:

String s = "4.3756";
int n = s.indexOf('.');
int characteristic=Integer.parseInt(s.substring(0,n));
int mantissa=Integer.valueOf(s.substring(n+1));

Answer

The value of characteristic is 4 and mantissa is 3756.

5/17
Index of . in String s is 1 so variable n is initialized to 1. s.substring(0,n) gives 4.
Integer.parseInt() converts string "4" into integer 4 and this 4 is assigned to the variable
characteristic.

s.substring(n+1) gives 3756 i.e. the string starting at index 2 till the end of s.
Integer.valueOf() converts string "3756" into integer 3756 and this value is assigned to the
variable mantissa.

(h) Study the method and answer the given questions.

public void sampleMethod()


{ for (int i=0; i < 3; i++)
{ for (int j = 0; j<2; j++)
{int number = (int)(Math.random() * 10);
System.out.println(number); }}}

1. How many times does the loop execute?


2. What is the range of possible values stored in the variable number?

Answer

1. The loops execute 6 times.


2. The range is from 0 to 9.

(i) Consider the following class:

public class myClass {


public static int x=3, y=4;
public int a=2, b=3;}

1. Name the variables for which each object of the class will have its own
distinct copy.
2. Name the variables that are common to all objects of the class.

Answer

1. a, b
2. x, y

(j) What will be the output when the following code segments are executed?

(i)

String s = "1001";
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println("x="+x);
System.out.println("y="+y);

(ii)

System.out.println("The king said \"Begin at the beginning!\" to me.");

6/17
Answer

(i) The output of the code is:

x=1001
y=1001.0

(ii) The output of the code is:

The king said "Begin at the beginning!" to me.

Section B

Question 4

Define a class named movieMagic with the following description:

Data Members Purpose

int year To store the year of release of a movie

String title To store the title of the movie

float rating To store the popularity rating of the movie


(minimum rating=0.0 and maximum rating=5.0)

Member
Methods Purpose

movieMagic() Default constructor to initialize numeric data members to 0 and String


data member to "".

void accept() To input and store year, title and rating

void display() To display the title of the movie and a message based on the rating as
per the table given below

Ratings Table

Rating Message to be displayed

0.0 to 2.0 Flop

2.1 to 3.4 Semi-Hit

3.5 to 4.4 Hit

4.5 to 5.0 Super-Hit

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

7/17
Answer

import java.util.Scanner;

public class movieMagic


{
private int year;
private String title;
private float rating;

public movieMagic() {
year = 0;
title = "";
rating = 0.0f;
}

public void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Title of Movie: ");
title = in.nextLine();
System.out.print("Enter Year of Movie: ");
year = in.nextInt();
System.out.print("Enter Rating of Movie: ");
rating = in.nextFloat();
}

public void display() {


String message = "Invalid Rating";
if (rating <= 2.0f)
message = "Flop";
else if (rating <= 3.4f)
message = "Semi-Hit";
else if (rating <= 4.4f)
message = "Hit";
else if (rating <= 5.0f)
message = "Super-Hit";

System.out.println(title);
System.out.println(message);
}

public static void main(String args[]) {


movieMagic obj = new movieMagic();
obj.accept();
obj.display();
}
}

Output

8/17
Question 5

A special two-digit number is such that when the sum of its digits is added to the product
of its digits, the result is equal to the original two-digit number.

Example: Consider the number 59.


Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59

Write a program to accept a two-digit number. Add the sum of its digits to the product of
its digits. If the value is equal to the number input, then display the message "Special two
—digit number" otherwise, display the message "Not a special two-digit number".

Answer

9/17
import java.util.Scanner;

public class KboatSpecialNumber


{
public void checkNumber() {

Scanner in = new Scanner(System.in);

System.out.print("Enter a 2 digit number: ");


int orgNum = in.nextInt();

int num = orgNum;


int count = 0, digitSum = 0, digitProduct = 1;

while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}

if (count != 2)
System.out.println("Invalid input, please enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit number");

}
}

Output

10/17
Question 6

Write a program to assign a full path and file name as given below. Using library
functions, extract and output the file path, file name and file extension separately as
shown.

Input
C:\Users\admin\Pictures\flower.jpg

Output
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg

Answer

11/17
import java.util.Scanner;

public class KboatFilepathSplit


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter full path: ");
String filepath = in.next();

char pathSep = '\\';


char dotSep = '.';

int pathSepIdx = filepath.lastIndexOf(pathSep);


System.out.println("Path:\t\t" + filepath.substring(0, pathSepIdx));

int dotIdx = filepath.lastIndexOf(dotSep);


System.out.println("File Name:\t" + filepath.substring(pathSepIdx + 1,
dotIdx));

System.out.println("Extension:\t" + filepath.substring(dotIdx + 1));


}
}

Output

Question 7

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

1. double area (double a, double b, double c) with three double arguments, returns the
area of a scalene triangle using the formula:
area = √(s(s-a)(s-b)(s-c))
where s = (a+b+c) / 2

12/17
2. double area (int a, int b, int height) with three integer arguments, returns the area of
a trapezium using the formula:
area = (1/2)height(a + b)
3. double area (double diagonal1, double diagonal2) with two double arguments,
returns the area of a rhombus using the formula:
area = 1/2(diagonal1 x diagonal2)

Answer

import java.util.Scanner;

public class KboatOverload


{
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
double x = s * (s-a) * (s-b) * (s-c);
double result = Math.sqrt(x);
return result;
}

double area (int a, int b, int height) {


double result = (1.0 / 2.0) * height * (a + b);
return result;
}

double area (double diagonal1, double diagonal2) {


double result = 1.0 / 2.0 * diagonal1 * diagonal2;
return result;
}
}

Output

Question 8

Using the switch statement, write a menu driven program to calculate the maturity amount
of a Bank Deposit.
The user is given the following options:

1. Term Deposit
2. Recurring Deposit

For option 1, accept principal (P), rate of interest(r) and time period in years(n). Calculate
and output the maturity amount(A) receivable using the formula:

A = P[1 + r / 100]n

For option 2, accept Monthly Installment (P), rate of interest (r) and time period in months
(n). Calculate and output the maturity amount (A) receivable using the formula:

A = P x n + P x (n(n+1) / 2) x r / 100 x 1 / 12

13/17
For an incorrect option, an appropriate error message should be displayed.

Answer

import java.util.Scanner;

public class KboatBankDeposit


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Term Deposit");
System.out.println("Type 2 for Recurring Deposit");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
double p = 0.0, r = 0.0, a = 0.0;
int n = 0;

switch (ch) {
case 1:
System.out.print("Enter Principal: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in years: ");
n = in.nextInt();
a = p * Math.pow(1 + r / 100, n);
System.out.println("Maturity amount = " + a);
break;

case 2:
System.out.print("Enter Monthly Installment: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in months: ");
n = in.nextInt();
a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
System.out.println("Maturity amount = " + a);
break;

default:
System.out.println("Invalid choice");
}
}
}

Output

14/17
15/17
Question 9

Write a program to accept the year of graduation from school as an integer value from the
user. Using the binary search technique on the sorted array of integers given below,
output the message "Record exists" if the value input is located in the array. If not, output
the message "Record does not exist".
Sample Input:

n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]

1982 1987 1993 1996 1999 2003 2006 2007 2009 2010

Answer

16/17
import java.util.Scanner;

public class KboatGraduationYear


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};

System.out.print("Enter graduation year to search: ");


int year = in.nextInt();

int l = 0, h = n.length - 1, idx = -1;


while (l <= h) {
int m = (l + h) / 2;
if (n[m] == year) {
idx = m;
break;
}
else if (n[m] < year) {
l = m + 1;
}
else {
h = m - 1;
}
}

if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}

Output

17/17
Solved 2015 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/zpDOM/year-
2015

2015

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) What are the default values of the primitive data type int and float?

Answer

Default value of int is 0 and float is 0.0f.

(b) Name any two OOP’s principles.

Answer

1. Encapsulation
2. Inheritance

(c) What are identifiers ?

Answer

Identifiers are symbolic names given to different parts of a program such as variables,
methods, classes, objects, etc.

(d) Identify the literals listed below:

(i) 0.5 (ii) 'A' (iii) false (iv) "a"

Answer

1. Real Literal
2. Character Literal
3. Boolean Literal
4. String Literal

(e) Name the wrapper classes of char type and boolean type.

Answer

1/17
Wrapper class of char type is Character and boolean type is Boolean.

Question 2

(a) Evaluate the value of n if value of p = 5, q = 19

int n = (q – p) > (p – q) ? (q – p) : (p – q);

Answer

int n = (q – p) > (p – q) ? (q – p) : (p – q)
⇒ int n = (19 - 5) > (5 - 19) ? (19 - 5) : (5 - 19)
⇒ int n = 14 > -14 ? 14 : -14
⇒ int n = 14 [∵ 14 > -14 is true so ? : returns 14]

Final value of n is 14

(b) Arrange the following primitive data types in an ascending order of their size:

(i) char (ii) byte (iii) double (iv) int

Answer

byte, char, int, double

(c) What is the value stored in variable res given below:

double res = Math.pow ("345".indexOf('5'), 3);

Answer

Value of res is 8.0


Index of '5' in "345" is 2. Math.pow(2, 3) means 23 which is equal to 8

(d) Name the two types of constructors

Answer

Parameterized constructors and Non-Parameterized constructors.

(e) What are the values of a and b after the following function is executed, if the
values passed are 30 and 50:

void paws(int a, int b)


{
a=a+b;
b=a–b;
a=a–b;
System.out.println(a+ "," +b);
}

Answer

2/17
Value of a is 50 and b is 30.
Output of the code is:

50,30

Question 3

(a) State the data type and value of y after the following is executed:

char x='7';
y=Character.isLetter(x);

Answer

Data type of y is boolean and value is false. Character.isLetter() method checks if its
argument is a letter or not and as 7 is a number not a letter hence it returns false.

(b) What is the function of catch block in exception handling ? Where does it
appear in a program ?

Answer

Catch block contains statements that we want to execute in case an exception is thrown
in the try block. Catch block appears immediately after the try block in a program.

(c) State the output when the following program segment is executed:

String a ="Smartphone", b="Graphic Art";


String h=a.substring(2, 5);
String k=b.substring(8).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));

Answer

The output of the above code is:

art
true

Explanation
a.substring(2, 5) extracts the characters of string a starting from index 2 till index 4. So h
contains the string "art". b.substring(8) extracts characters of b from index 8 till the end so
it returns "Art". toUpperCase() converts it into uppercase. Thus string "ART" gets
assigned to k. Values of h and k are "art" and "ART", respectively. As both h and k differ in
case only hence equalsIgnoreCase returns true.

(d) The access specifier that gives the most accessibility is ________ and the least
accessibility is ________.

Answer

3/17
The access specifier that gives the most accessibility is public and the least accessibility
is private.

(e) (i) Name the mathematical function which is used to find sine of an angle given
in radians.
(ii) Name a string function which removes the blank spaces provided in the prefix
and suffix of a string.

Answer

(i) Math.sin() (ii) trim()

(f) (i) What will this code print ?

int arr[]=new int[5];


System.out.println(arr);

1. 0
2. value stored in arr[0]
3. 0000
4. garbage value

Answer

This code will print garbage value

(ii) Name the keyword which is used- to resolve the conflict between method
parameter and instance variables/fields.

Answer

this keyword

(g) State the package that contains the class:

1. BufferedReader
2. Scanner

Answer

1. java.io
2. java.util

(h) Write the output of the following program code:

4/17
char ch ;
int x=97;
do
{
ch=(char)x;
System.out.print(ch + " " );
if(x%10 == 0)
break;
++x;
} while(x<=100);

Answer
The output of the above code is:

a b c d

Explanation
The below table shows the dry run of the program:

x ch Output Remarks

97 a a 1st Iteration

98 b ab 2nd Iteration

99 c abc 3rd Iteration

100 d abcd 4th Iteration — As x%10 becomes true, break statement is


executed and exists the loop.

(i) Write the Java expressions for:

2aba2+b2​

Answer

(a * a + b * b) / (2 * a * b)

(j) If int y = 10 then find int z = (++y * (y++ + 5));

Answer

z = (++y * (y++ + 5))


⇒ z = (11 * (11 + 5))
⇒ z = (11 * 16)
⇒ z = 176

Section B

Question 4

Define a class called ParkingLot with the following description:

5/17
Instance variables/data members:
int vno — To store the vehicle number.
int hours — To store the number of hours the vehicle is parked in the parking lot.
double bill — To store the bill amount.

Member Methods:
void input() — To input and store the vno and hours.
void calculate() — To compute the parking charge at the rate of ₹3 for the first hour or
part thereof, and ₹1.50 for each additional hour or part thereof.
void display() — To display the detail.

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

Answer

import java.util.Scanner;

public class ParkingLot


{
private int vno;
private int hours;
private double bill;

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter vehicle number: ");
vno = in.nextInt();
System.out.print("Enter hours: ");
hours = in.nextInt();
}

public void calculate() {


if (hours <= 1)
bill = 3;
else
bill = 3 + (hours - 1) * 1.5;
}

public void display() {


System.out.println("Vehicle number: " + vno);
System.out.println("Hours: " + hours);
System.out.println("Bill: " + bill);
}

public static void main(String args[]) {


ParkingLot obj = new ParkingLot();
obj.input();
obj.calculate();
obj.display();
}
}

Output

6/17
Question 5

Write two separate programs to generate the following patterns using iteration (loop)
statements:

(a)

*
* #
* # *
* # * #
* # * # *

(b)

54321
5432
543
54
5

Answer

7/17
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}

Output

public class KboatPattern


{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 5; j >= i; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}

Output

8/17
Question 6

Write a program to input and store roll numbers, names and marks in 3 subjects of n
number of students in five single dimensional arrays and display the remark based on
average marks as given below:

Average Marks Remark

85 — 100 Excellent

75 — 84 Distinction

60 — 74 First Class

40 — 59 Pass

Less than 40 Poor

Answer

9/17
import java.util.Scanner;

public class KboatAvgMarks


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter number of students: ");
int n = in.nextInt();

int rollNo[] = new int[n];


String name[] = new String[n];
int s1[] = new int[n];
int s2[] = new int[n];
int s3[] = new int[n];
double avg[] = new double[n];

for (int i = 0; i < n; i++) {


System.out.println("Enter student " + (i+1) + " details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
in.nextLine();
System.out.print("Name: ");
name[i] = in.nextLine();
System.out.print("Subject 1 Marks: ");
s1[i] = in.nextInt();
System.out.print("Subject 2 Marks: ");
s2[i] = in.nextInt();
System.out.print("Subject 3 Marks: ");
s3[i] = in.nextInt();
avg[i] = (s1[i] + s2[i] + s3[i]) / 3.0;
}

System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++) {
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ remark);
}
}
}

Output

10/17
11/17
Question 7

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

1. void Joystring(String s, char ch1, char ch2) with one string argument and two
character arguments that replaces the character argument ch1 with the character
argument ch2 in the given String s and prints the new string.
Example:
Input value of s = "TECHNALAGY"
ch1 = 'A'
ch2 = 'O'
Output: "TECHNOLOGY"

12/17
2. void Joystring(String s) with one string argument that prints the position of the first
space and the last space of the given String s.
Example:
Input value of s = "Cloud computing means Internet based computing"
Output:
First index: 5
Last Index: 36
3. void Joystring(String s1, String s2) with two string arguments that combines the two
strings with a space between them and prints the resultant string.
Example:
Input value of s1 = "COMMON WEALTH"
Input value of s2 = "GAMES"
Output: COMMON WEALTH GAMES

(Use library functions)

Answer

public class KboatStringOverload


{
public void joystring(String s, char ch1, char ch2) {
String newStr = s.replace(ch1, ch2);
System.out.println(newStr);
}

public void joystring(String s) {


int f = s.indexOf(' ');
int l = s.lastIndexOf(' ');
System.out.println("First index: " + f);
System.out.println("Last index: " + l);
}

public void joystring(String s1, String s2) {


String newStr = s1.concat(" ").concat(s2);
System.out.println(newStr);
}

public static void main(String args[]) {


KboatStringOverload obj = new KboatStringOverload();
obj.joystring("TECHNALAGY", 'A', 'O');
obj.joystring("Cloud computing means Internet based computing");
obj.joystring("COMMON WEALTH", "GAMES");
}
}

Output

13/17
Question 8

Write a program to input twenty names in an array. Arrange these names in descending
order of letters, using the bubble sort technique.

Answer

import java.util.Scanner;

public class KboatArrangeNames


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String names[] = new String[20];
System.out.println("Enter 20 names:");
for (int i = 0; i < names.length; i++) {
names[i] = in.nextLine();
}

//Bubble Sort
for (int i = 0; i < names.length - 1; i++) {
for (int j = 0; j < names.length - 1 - i; j++) {
if (names[j].compareToIgnoreCase(names[j + 1]) < 0) {
String temp = names[j + 1];
names[j + 1] = names[j];
names[j] = temp;
}
}
}

System.out.println("\nSorted Names");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}
}

14/17
Output

Question 9

Using switch statement, write a menu driven program to:


(i) To find and display all the factors of a number input by the user ( including 1 and the
excluding the number itself).
Example:
Sample Input : n = 15
Sample Output : 1, 3, 5

15/17
(ii) To find and display the factorial of a number input by the user (the factorial of a non-
negative integer n, denoted by n!, is the product of all integers less than or equal to n.)
Example:
Sample Input : n = 5
Sample Output : 5! = 1*2*3*4*5 = 120

For an incorrect choice, an appropriate error message should be displayed.

Answer

import java.util.Scanner;

public class KboatMenu


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Factors of number");
System.out.println("2. Factorial of number");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
int num;

switch (choice) {
case 1:
System.out.print("Enter number: ");
num = in.nextInt();
for (int i = 1; i < num; i++) {
if (num % i == 0) {
System.out.print(i + " ");
}
}
System.out.println();
break;

case 2:
System.out.print("Enter number: ");
num = in.nextInt();
int f = 1;
for (int i = 1; i <= num; i++)
f *= i;
System.out.println("Factorial = " + f);
break;

default:
System.out.println("Incorrect Choice");
break;
}
}
}

Output

16/17
17/17
Solved 2016 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/qM0BW/year-
2016

2016

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) Define Encapsulation.

Answer

Encapsulation is a mechanism that binds together code and the data it manipulates. It
keeps them both safe from the outside world, preventing any unauthorised access or
misuse. Only member methods, which are wrapped inside the class, can access the data
and other methods.

(b) What are keywords ? Give an example.

Answer

Keywords are reserved words that have a special meaning to the Java compiler.
Example: class, public, int, etc.

(c) Name any two library packages.

Answer

Two library packages are:

1. java.io
2. java.util

(d) Name the type of error ( syntax, runtime or logical error) in each case given
below:

1. Math.sqrt (36 – 45)


2. int a;b;c;

Answer

1/19
1. Runtime Error
2. Syntax Error

(e) If int x[] = { 4, 3, 7, 8, 9, 10}; what are the values of p and q ?

1. p = x.length
2. q = x[2] + x[5] * x[1]

Answer

1. 6
2. q = x[2] + x[5] * x[1]
q = 7 + 10 * 3
q = 7 + 30
q = 37

Question 2

(a) State the difference between == operator and equals() method.

Answer

equals() ==

It is a method It is a relational operator

It is used to check if the contents of two It is used to check if two variables refer to
strings are same or not the same object in memory

Example: Example:
String s1 = new String("hello"); String s1 = new String("hello");
String s2 = new String("hello"); String s2 = new String("hello");
boolean res = s1.equals(s2); boolean res = s1 == s2;
System.out.println(res); System.out.println(res);

The output of this code snippet is true as The output of this code snippet is false as
contents of s1 and s2 are the same. s1 and s2 point to different String objects.

(b) What are the types of casting shown by the following examples:

1. char c = (char) 120;


2. int x = ‘t’;

Answer

1. Explicit Cast.
2. Implicit Cast.

(c) Differentiate between formal parameter and actual parameter.

Answer

2/19
Formal parameter Actual parameter

Formal parameters appear in function Actual parameters appear in function call


definition. statement.

They represent the values received by the They represent the values passed to the
called function. called function.

(d) Write a function prototype of the following:


A function PosChar which takes a string argument and a character argument and
returns an integer value.

Answer

int PosChar(String s, char ch)

(e) Name any two types of access specifiers.

Answer

1. public
2. private

Question 3

(a) Give the output of the following string functions:

1. "MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
2. "CABLE".compareTo("CADET")

Answer

1. 2 + 10 = 12
2. ASCII Code of B - ASCII Code of D
⇒ 66 - 68
⇒ -2

(b) Give the output of the following Math functions:

1. Math.ceil(4.2)
2. Math.abs(-4)

Answer

1. 5.0
2. 4

(c) What is a parameterized constructor ?

Answer

3/19
A Parameterised constructor receives parameters at the time of creating an object and
initializes the object with the received values.

(d) Write down java expression for:

T=A2+B2+C2 ​

Answer

T = Math.sqrt(a*a + b*b + c*c)

(e) Rewrite the following using ternary operator:

if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");

Answer

System.out.print(x%2 == 0 ? "EVEN" : "ODD");

(f) Convert the following while loop to the corresponding for loop:

int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n--;
}

Answer

int m = 5;
for (int n = 10; n >= 1; n--) {
System.out.println(m*n);
}

(g) Write one difference between primitive data types and composite data types.

Answer

Primitive Data Types are built-in data types defined by Java language specification
whereas Composite Data Types are defined by the programmer.

(h) Analyze the given program segment and answer the following questions:

1. Write the output of the program segment.


2. How many times does the body of the loop gets executed ?

4/19
for(int m = 5; m <= 20; m += 5)
{ if(m % 3 == 0)
break;
else
if(m % 5 == 0)
System.out.println(m);
continue;
}

Answer

Output

5
10

Loop executes 3 times.

Below dry run of the loop explains its working.

m Output Remarks

5 5 1st Iteration

10 5 2nd Iteration
10

15 5 3rd Iteration — As m % 3 becomes true, break statement exists the loop.


10

(i) Give the output of the following expression:

a+= a++ + ++a + --a + a-- ; when a = 7

Answer

a+= a++ + ++a + --a + a--


⇒ a = a + (a++ + ++a + --a + a--)
⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39

(j) Write the return type of the following library functions:

1. isLetterOrDigit(char)
2. replace(char, char)

Answer

1. boolean
2. String

5/19
Section B

Question 4

Define a class named BookFair with the following description:

Instance variables/Data members:


String Bname — stores the name of the book
double price — stores the price of the book

Member methods:
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based
on the following criteria.

Price Discount

Less than or equal to ₹1000 2% of price

More than ₹1000 and less than or equal to ₹3000 10% of price

More than ₹3000 15% of price

(iv) void display() — To display the name and price of the book after discount.

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

Answer

6/19
import java.util.Scanner;

public class BookFair


{
private String bname;
private double price;

public BookFair() {
bname = "";
price = 0.0;
}

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter name of the book: ");
bname = in.nextLine();
System.out.print("Enter price of the book: ");
price = in.nextDouble();
}

public void calculate() {


double disc;
if (price <= 1000)
disc = price * 0.02;
else if (price <= 3000)
disc = price * 0.1;
else
disc = price * 0.15;

price -= disc;
}

public void display() {


System.out.println("Book Name: " + bname);
System.out.println("Price after discount: " + price);
}

public static void main(String args[]) {


BookFair obj = new BookFair();
obj.input();
obj.calculate();
obj.display();
}
}

Output

7/19
Question 5

Using the switch statement, write a menu driven program for the following:

(i) To print the Floyd’s triangle [Given below]

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

(b) To display the following pattern:


I
IC
ICS
ICSE

For an incorrect option, an appropriate error message should be displayed.

Answer

8/19
import java.util.Scanner;

public class KboatPattern


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Floyd's triangle");
System.out.println("Type 2 for an ICSE pattern");

System.out.print("Enter your choice: ");


int ch = in.nextInt();

switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;

case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;

default:
System.out.println("Incorrect Choice");
}
}
}

Output

9/19
10/19
Question 6

Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-
versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.

Write a program to accept a word. Check and display whether the word is a palindrome or
only a special word or none of them.

Answer

11/19
import java.util.Scanner;

public class KboatSpecialPalindrome


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.next();
str = str.toUpperCase();
int len = str.length();

if (str.charAt(0) == str.charAt(len - 1)) {


boolean isPalin = true;
for (int i = 1; i < len / 2; i++) {
if (str.charAt(i) != str.charAt(len - 1 - i)) {
isPalin = false;
break;
}
}

if (isPalin) {
System.out.println("Palindrome");
}
else {
System.out.println("Special");
}
}
else {
System.out.println("Neither Special nor Palindrome");
}

}
}

Output

12/19
Question 7

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

(i) void sumSeries(int n, double x): with one integer argument and one double argument
to find and display the sum of the series given below:

s=1x​−2x​+3x​−4x​+5x​... ... ... to n terms

(ii) void sumSeries(): to find and display the sum of the following series:

s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×20)

Answer

13/19
public class KboatOverload
{
void sumSeries(int n, double x) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double t = x / i;
if (i % 2 == 0)
sum -= t;
else
sum += t;
}
System.out.println("Sum = " + sum);
}

void sumSeries() {
long sum = 0, term = 1;
for (int i = 1; i <= 20; i++) {
term *= i;
sum += term;
}
System.out.println("Sum=" + sum);
}
}

Output

14/19
Question 8

Write a program to accept a number and check and display whether it is a Niven number
or not.
(Niven number is that number which is divisible by its sum of digits.).

Example:
Consider the number 126. Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.

Answer

15/19
import java.util.Scanner;

public class KboatNivenNumber


{
public void checkNiven() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int num = in.nextInt();
int orgNum = num;

int digitSum = 0;

while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
}

/*
* digitSum != 0 check prevents
* division by zero error for the
* case when users gives the number
* 0 as input
*/
if (digitSum != 0 && orgNum % digitSum == 0)
System.out.println(orgNum + " is a Niven number");
else
System.out.println(orgNum + " is not a Niven number");
}
}

Output

16/19
Question 9

Write a program to initialize the seven Wonders of the World along with their locations in
two different arrays. Search for a name of the country input by the user. If found, display
the name of the country along with its Wonder, otherwise display "Sorry not found!".

Seven Wonders:
CHICHEN ITZA, CHRIST THE REDEEMER, TAJ MAHAL, GREAT WALL OF CHINA,
MACHU PICCHU, PETRA, COLOSSEUM

Locations:
MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY

Examples:
Country name: INDIA
Output: TAJ MAHAL

Country name: USA


Output: Sorry Not found!

Answer

17/19
import java.util.Scanner;

public class Kboat7Wonders


{
public static void main(String args[]) {

String wonders[] = {"CHICHEN ITZA", "CHRIST THE REDEEMER", "TAJMAHAL",


"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA", "COLOSSEUM"};

String locations[] = {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU",


"JORDAN",
"ITALY"};

Scanner in = new Scanner(System.in);


System.out.print("Enter country: ");
String c = in.nextLine();
int i;

for (i = 0; i < locations.length; i++) {


if (locations[i].equals(c)) {
System.out.println(locations[i] + " - " + wonders[i]);
break;
}
}

if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}

Output

18/19
19/19
Solved 2017 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/EKMvz/year-
2017

2017

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) What is inheritance?

Answer

Inheritance is the mechanism by which a class acquires the properties and methods of
another class.

(b) Name the operators listed below:

1. <
2. ++
3. &&
4. ? :

Answer

1. Less than operator. (It is a relational operator)


2. Increment operator. (It is an arithmetic operator)
3. Logical AND operator. (It is a logical operator)
4. Ternary operator. (It is a conditional operator)

(c) State the number of bytes occupied by char and int data types.

Answer

char occupies 2 bytes and int occupies 4 bytes.

(d) Write one difference between / and % operator.

Answer

/ operator computes the quotient whereas % operator computes the remainder.

1/19
(e) String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};

Give the output of the following statements:

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

Answer

1. The output of System.out.println(x[1]); is NOKIA. x[1] gives the second


element of the array x which is "NOKIA"

2. The output of System.out.println(x[3].length()); is 8. x[3].length() gives


the number of characters in the fourth element of the array x which is MICROMAX.

Question 2

(a) Name the following:

1. A keyword used to call a package in the program.


2. Any one reference data type.

Answer

1. import
2. Array

(b) What are the two ways of invoking functions?

Answer

Call by value and call by reference.

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

char ch='t';
res= Character.toUpperCase(ch);

Answer

Data type of res is char and its value is T.

(d) Give the output of the following program segment and also mention the number
of times the loop is executed:

int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a%b == 0)
break;
}
System.out.println(a);

2/19
Answer

Output of the above code is 12 and loop executes 2 times.

Explanation
This dry run explains the working of the loop.

a b Remarks

6 4 1st Iteration

12 4 2nd Iteration

In 2nd iteration, as a%b becomes 0 so break statement is executed and the loop exits.
Program control comes to the println statement which prints the output as current value of
a which is 12.

(e) Write the output:

char ch = 'F';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);

Answer

Output of the above code is:

75 F

Explanation

The statement int m = ch; assigns the ASCII value of F (which is 70) to variable m.
Adding 5 to m makes it 75. In the println statement, the current value of m which is 75 is
printed followed by space and then value of ch which is F.

Question 3

(a) Write a Java expression for the following:


ax5 + bx3 + c

Answer

a * Math.pow(x, 5) + b * Math.pow(x, 3) + c

(b) What is the value of x1 if x=5?


x1= ++x – x++ + --x

Answer

3/19
x1 = ++x – x++ + --x
⇒ x1 = 6 - 6 + 6
⇒ x1 = 0 + 6
⇒ x1 = 6

(c) Why is an object called an instance of a class?

Answer

A class can create objects of itself with different characteristics and common behaviour.
So, we can say that an Object represents a specific state of the class. For these reasons,
an Object is called an Instance of a Class.

(d) Convert following do-while loop into for loop.

int i = 1;
int d = 5;
do {
d=d*2;
System.out.println(d);
i++ ; } while ( i<=5);

Answer

int i = 1;
int d = 5;
for (i = 1; i <= 5; i++) {
d=d*2;
System.out.println(d);
}

(e) Differentiate between constructor and function.

Answer

Constructor Function

Constructor is a block of code Function is a group of statements that can be called at


that initializes a newly created any point in the program using its name to perform a
object. specific task.

Constructor has the same Function should have a different name than class
name as class name. name.

Constructor has no return Function requires a valid return type.


type not even void.

(f) Write the output for the following:

String s="Today is Test";


System.out.println(s.indexOf('T'));
System.out.println(s.substring(0,7) + " " +"Holiday");

4/19
Answer

Output of the above code is:

0
Today i Holiday

Explanation
As the first T is present at index 0 in string s so s.indexOf('T') returns 0.
s.substring(0,7) extracts the characters from index 0 to index 6 of string s. So its result is
Today i. After that println statement prints Today i followed by a space and Holiday.

(g) What are the values stored in variables r1 and r2:

1. double r1 = Math.abs(Math.min(-2.83, -5.83));


2. double r2 = Math.sqrt(Math.floor(16.3));

Answer

1. r1 has 5.83
2. r2 has 4.0

Explanation
1. Math.min(-2.83, -5.83) returns -5.83 as -5.83 is less than -2.83. (Note that these are
negative numbers). Math.abs(-5.83) returns 5.83.
2. Math.floor(16.3) returns 16.0. Math.sqrt(16.0) gives square root of 16.0 which is 4.0.

(h) Give the output of the following code:

String A ="26", B="100";


String D=A+B+"200";
int x= Integer.parseInt(A);
int y = Integer.parseInt(B);
int d = x+y;
System.out.println("Result 1 = " + D);
System.out.println("Result 2 = " + d);

Answer

Output of the above code is:

Result 1 = 26100200
Result 2 = 126

Explanation
1. As A and B are strings so String D=A+B+"200"; joins A, B and "200" storing the
string "26100200" in D.
2. Integer.parseInt() converts strings A and B into their respective numeric values.
Thus, x becomes 26 and y becomes 100.
3. As Java is case-sensitive so D and d are treated as two different variables.

5/19
4. Sum of x and y is assigned to d. Thus, d gets a value of 126.

(i) Analyze the given program segment and answer the following questions:

for(int i=3;i<=4;i++ ) {
for(int j=2;j<i;j++ ) {
System.out.print("" ); }
System.out.println("WIN" ); }

1. How many times does the inner loop execute?


2. Write the output of the program segment.

Answer

1. Inner loop executes 3 times.


(For 1st iteration of outer loop, inner loop executes once. For 2nd iteration of outer
loop, inner loop executes two times.)

2. Output:
WIN
WIN

(j) What is the difference between the Scanner class functions next() and
nextLine()?

Answer

next() nextLine()

It reads the input only till space so it It reads the input till the end of line so it can
can read only a single word. read a full sentence including spaces.

It places the cursor in the same line It places the cursor in the next line after reading
after reading the input. the input.

Section B

Question 4

Define a class ElectricBill with the following specifications:

class : ElectricBill

Instance variables / data member:


String n — to store the name of the customer
int units — to store the number of units consumed
double bill — to store the amount to be paid

6/19
Member methods:
void accept( ) — to accept the name of the customer and number of units consumed
void calculate( ) — to calculate the bill as per the following tariff:

Number of units Rate per unit

First 100 units Rs.2.00

Next 200 units Rs.3.00

Above 300 units Rs.5.00

A surcharge of 2.5% charged if the number of units consumed is above 300 units.

void print( ) — To print the details as follows:


Name of the customer: ………………………
Number of units consumed: ………………………
Bill amount: ………………………

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

Answer

7/19
import java.util.Scanner;

public class ElectricBill


{
private String n;
private int units;
private double bill;

public void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter customer name: ");
n = in.nextLine();
System.out.print("Enter units consumed: ");
units = in.nextInt();
}

public void calculate() {


if (units <= 100)
bill = units * 2;
else if (units <= 300)
bill = 200 + (units - 100) * 3;
else {
double amt = 200 + 600 + (units - 300) * 5;
double surcharge = (amt * 2.5) / 100.0;
bill = amt + surcharge;
}
}

public void print() {


System.out.println("Name of the customer\t\t: " + n);
System.out.println("Number of units consumed\t: " + units);
System.out.println("Bill amount\t\t\t: " + bill);
}

public static void main(String args[]) {


ElectricBill obj = new ElectricBill();
obj.accept();
obj.calculate();
obj.print();
}
}

Output

8/19
Question 5

Write a program to accept a number and check and display whether it is a spy number or
not. (A number is spy if the sum of its digits equals the product of its digits.)

Example: consider the number 1124.


Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 x 1 x 2 x 4 = 8

Answer

9/19
import java.util.Scanner;

public class KboatSpyNumber


{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter Number: ");


int num = in.nextInt();

int digit, sum = 0;


int orgNum = num;
int prod = 1;

while (num > 0) {


digit = num % 10;

sum += digit;
prod *= digit;
num /= 10;
}

if (sum == prod)
System.out.println(orgNum + " is Spy Number");
else
System.out.println(orgNum + " is not Spy Number");

}
}

Output

10/19
Question 6

Using switch statement, write a menu driven program for the following:

1. To find and display the sum of the series given below:


S = x1 - x2 + x3 - x4 + x5 .......... - x20
(where x = 2)
2. To display the following series:
1 11 111 1111 11111

For an incorrect option, an appropriate error message should be displayed.

Answer

11/19
import java.util.Scanner;

public class KboatSeriesMenu


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("1. Sum of the series");
System.out.println("2. Display series");
System.out.print("Enter your choice: ");
int choice = in.nextInt();

switch (choice) {
case 1:
int sum = 0;
for (int i = 1; i <= 20; i++) {
int x = 2;
int term = (int)Math.pow(x, i);
if (i % 2 == 0)
sum -= term;
else
sum += term;
}
System.out.println("Sum=" + sum);
break;

case 2:
int term = 1;
for (int i = 1; i <= 5; i++) {
System.out.print(term + " ");
term = term * 10 + 1;
}
break;

default:
System.out.println("Incorrect Choice");
break;
}
}
}

Output

12/19
Question 7

Write a program to input integer elements into an array of size 20 and perform the
following operations:

1. Display largest number from the array.


2. Display smallest number from the array.
3. Display sum of all the elements of the array

Answer

13/19
import java.util.Scanner;

public class KboatSDAMinMaxSum


{
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 < 20; i++) {
arr[i] = in.nextInt();
}
int min = arr[0], max = arr[0], sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < min)
min = arr[i];

if (arr[i] > max)


max = arr[i];

sum += arr[i];
}

System.out.println("Largest Number = " + max);


System.out.println("Smallest Number = " + min);
System.out.println("Sum = " + sum);
}
}

Output

14/19
Question 8

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

1. void check (String str , char ch ) — to find and print the frequency of a character in a
string.
Example:
Input:
str = "success"
ch = 's'
Output:
number of s present is = 3

15/19
2. void check(String s1) — to display only vowels from string s1, after converting it to
lower case.
Example:
Input:
s1 ="computer"
Output : o u e

Answer

public class KboatOverload


{
void check (String str , char ch ) {
int count = 0;
int len = str.length();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (ch == c) {
count++;
}
}
System.out.println("Frequency of " + ch + " = " + count);
}

void check(String s1) {


String s2 = s1.toLowerCase();
int len = s2.length();
System.out.println("Vowels:");
for (int i = 0; i < len; i++) {
char ch = s2.charAt(i);
if (ch == 'a' ||
ch == 'e' ||
ch == 'i' ||
ch == 'o' ||
ch == 'u')
System.out.print(ch + " ");
}
}
}

Output

16/19
Question 9

Write a program to input forty words in an array. Arrange these words in descending order
of alphabets, using selection sort technique. Print the sorted array.

Answer

17/19
import java.util.Scanner;

public class KboatSelectionSort


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String a[] = new String[40];
int n = a.length;

System.out.println("Enter 40 Names: ");


for (int i = 0; i < n; i++) {
a[i] = in.nextLine();
}

for (int i = 0; i < n - 1; i++) {


int idx = i;
for (int j = i + 1; j < n; j++) {
if (a[j].compareToIgnoreCase(a[idx]) < 0) {
idx = j;
}
}
String t = a[idx];
a[idx] = a[i];
a[i] = t;
}

System.out.println("Sorted Names");
for (int i = 0; i < n; i++) {
System.out.println(a[i]);
}
}
}

Output

18/19
19/19
Solved 2018 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/Vgz3r/year-2018

2018

Class 10 - ICSE Computer Applications Solved Question Papers

Section A

Question 1

(a) Define abstraction.

Answer

Abstraction refers to the act of representing essential features without including the
background details or explanation.

(b) Differentiate between searching and sorting.

Answer

Searching Sorting

Searching means to search for a Sorting means to arrange the elements of the
term or value in an array. array in ascending or descending order.

Linear search and Binary search are Bubble sort and Selection sort are examples of
examples of search techniques. sorting techniques.

(c) Write a difference between the functions isUpperCase( ) and toUpperCase( ).

Answer

isUpperCase( ) toUpperCase( )

isUpperCase( ) function checks if a given toUpperCase( ) function converts a


character is in uppercase or not. given character to uppercase.

Its return type is boolean. Its return type is char.

(d) How are private members of a class different from public members?

Answer

1/17
private members of a class can only be accessed by other member methods of the same
class whereas public members of a class can be accessed by methods of other classes
as well.

(e) Classify the following as primitive or non-primitive datatypes:

1. char
2. arrays
3. int
4. classes

Answer

1. Primitive
2. Non-Primitive
3. Primitive
4. Non-Primitive

Question 2

(a) (i) int res = 'A';


What is the value of res?

Answer

Value of res is 65 which is the ASCII code of A. As res is an int variable and we are trying
to assign it the character A so through implicit type conversion the ASCII code of A is
assigned to res.

(ii) Name the package that contains wrapper classes.

Answer

java.lang

(b) State the difference between while and do while loop.

Answer

while do-while

It is an entry-controlled loop. It is an exit-controlled loop.

It is helpful in situations where numbers of It is suitable when we need to display


iterations are not known. a menu to the user.

(c) System.out.print("BEST ");


System.out.println("OF LUCK");

Choose the correct option for the output of the above statements

2/17
1. BEST OF LUCK
2. BEST
OF LUCK

Answer

Option 1 — BEST OF LUCK is the correct option.


System.out.print does not print a newline at the end of its output so the println statement
begins printing on the same line. So the output is BEST OF LUCK printed on a single line.

(d) Write the prototype of a function check which takes an integer as an argument
and returns a character.

Answer

char check(int a)

(e) Write the return data type of the following function.

1. endsWith()
2. log()

Answer

1. boolean
2. double

Question 3

(a) Write a Java expression for the following:

a+b3x+x2 ​

Answer

Math.sqrt(3 * x + x * x) / (a + b)

(b) What is the value of y after evaluating the expression given below?

y+= ++y + y-- + --y; when int y=8

Answer

y+= ++y + y-- + --y


⇒ y = y + (++y + y-- + --y)
⇒ y = 8 + (9 + 9 + 7)
⇒ y = 8 + 25
⇒ y = 33

(c) Give the output of the following:

3/17
1. Math.floor (-4.7)
2. Math.ceil(3.4) + Math.pow(2, 3)

Answer

1. -5.0
2. 12.0

(d) Write two characteristics of a constructor.

Answer

Two characteristics of a constructor are:

1. A constructor has the same name as its class.


2. A constructor does not have a return type.

(e) Write the output for the following:

System.out.println("Incredible"+"\n"+"world");

Answer

Output of the above code is:

Incredible
world

\n is the escape sequence for newline so Incredible and world are printed on two different
lines.

(f) Convert the following if else if construct into switch case

if( var==1)
System.out.println("good");
else if(var==2)
System.out.println("better");
else if(var==3)
System.out.println("best");
else
System.out.println("invalid");

Answer

4/17
switch (var) {
case 1:
System.out.println("good");
break;

case 2:
System.out.println("better");
break;

case 3:
System.out.println("best");
break;

default:
System.out.println("invalid");
}

(g) Give the output of the following string functions:

1. "ACHIEVEMENT".replace('E', 'A')
2. "DEDICATE".compareTo("DEVOTE")

Answer

1. ACHIAVAMANT
2. -18

Explanation
1. "ACHIEVEMENT".replace('E', 'A') will replace all the E's in ACHIEVEMENT with A's.
2. The first letters that are different in DEDICATE and DEVOTE are D and V
respectively. So the output will be:
ASCII code of D - ASCII code of V
⇒ 68 - 86
⇒ -18

(h) Consider the following String array and give the output

String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};


System.out.println(arr[0].length() > arr[3].length());
System.out.print(arr[4].substring(0,3));

Answer

Output of the above code is:

false
JAI

Explanation
1. arr[0] is DELHI and arr[3] is LUCKNOW. Length of DELHI is 5 and LUCKNOW is 7.
As 5 > 7 is false so the output is false.

5/17
2. arr[4] is JAIPUR. arr[4].substring(0,3) extracts the characters from index 0 till index
2 of JAIPUR so JAI is the output.

(i) Rewrite the following using ternary operator:

if (bill > 10000 )


discount = bill * 10.0/100;
else
discount = bill * 5.0/100;

Answer

discount = bill > 10000 ? bill * 10.0/100 : bill * 5.0/100;

(j) Give the output of the following program segment and also mention how many
times the loop is executed:

int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i );
System.out.println( i * 4 );

Answer

Output of the above code is:

20

Loop executes 0 times.

Explanation
In the loop, i is initialized to 5 but the condition of the loop is i > 10. As 5 is less than 10 so
the condition of the loop is false and it is not executed. There are no curly braces after the
loop which means that the statement System.out.println( i ); is inside the loop and
the statement System.out.println( i * 4 ); is outside the loop. Loop is not executed
so System.out.println( i ); is not executed but System.out.println( i * 4 );
being outside the loop is executed and prints the output as 20 (i * 4 ⇒ 5 * 4 ⇒ 20).

Section B

Question 4

Design a class RailwayTicket with following description:

Instance variables/data members:


String name — To store the name of the customer
String coach — To store the type of coach customer wants to travel
long mobno — To store customer’s mobile number
int amt — To store basic amount of ticket
int totalamt — To store the amount to be paid after updating the original amount

6/17
Member methods:
void accept() — To take input for name, coach, mobile number and amount.
void update() — To update the amount as per the coach selected (extra amount to be
added in the amount as follows)

Type of Coaches Amount

First_AC 700

Second_AC 500

Third_AC 250

sleeper None

void display() — To display all details of a customer such as name, coach, total amount
and mobile number.

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

Answer

7/17
import java.util.Scanner;

public class RailwayTicket


{
private String name;
private String coach;
private long mobno;
private int amt;
private int totalamt;

private void accept() {


Scanner in = new Scanner(System.in);
System.out.print("Enter name: ");
name = in.nextLine();
System.out.print("Enter coach: ");
coach = in.nextLine();
System.out.print("Enter mobile no: ");
mobno = in.nextLong();
System.out.print("Enter amount: ");
amt = in.nextInt();
}

private void update() {


if(coach.equalsIgnoreCase("First_AC"))
totalamt = amt + 700;
else if(coach.equalsIgnoreCase("Second_AC"))
totalamt = amt + 500;
else if(coach.equalsIgnoreCase("Third_AC"))
totalamt = amt + 250;
else if(coach.equalsIgnoreCase("Sleeper"))
totalamt = amt;
}

private void display() {


System.out.println("Name: " + name);
System.out.println("Coach: " + coach);
System.out.println("Total Amount: " + totalamt);
System.out.println("Mobile number: " + mobno);
}

public static void main(String args[]) {


RailwayTicket obj = new RailwayTicket();
obj.accept();
obj.update();
obj.display();
}
}

Output

8/17
Question 5

Write a program to input a number and check and print whether it is a Pronic number or
not. (Pronic number is the number which is the product of two consecutive integers)

Examples:
12 = 3 x 4
20 = 4 x 5
42 = 6 x 7

Answer

9/17
import java.util.Scanner;

public class KboatPronicNumber


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number to check: ");
int num = in.nextInt();

boolean isPronic = false;

for (int i = 1; i <= num - 1; i++) {


if (i * (i + 1) == num) {
isPronic = true;
break;
}
}

if (isPronic)
System.out.println(num + " is a pronic number");
else
System.out.println(num + " is not a pronic number");
}
}

Output

Question 6

10/17
Write a program in Java to accept a string in lower case and change the first letter of
every word to upper case. Display the new string.

Sample input: we are in cyber world


Sample output: We Are In Cyber World

Answer

import java.util.Scanner;

public class KboatString


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
String word = "";

for (int i = 0; i < str.length(); i++) {


if (i == 0 || str.charAt(i - 1) == ' ') {
word += Character.toUpperCase(str.charAt(i));
}
else {
word += str.charAt(i);
}
}

System.out.println(word);
}
}

Output

Question 7

11/17
Design a class to overload a function volume() as follows:

1. double volume (double R) – with radius (R) as an argument, returns the volume of
sphere using the formula.
V = 4/3 x 22/7 x R3

2. double volume (double H, double R) – with height(H) and radius(R) as the


arguments, returns the volume of a cylinder using the formula.
V = 22/7 x R2 x H

3. double volume (double L, double B, double H) – with length(L), breadth(B) and


Height(H) as the arguments, returns the volume of a cuboid using the formula.
V=LxBxH

Answer

public class KboatVolume


{
double volume(double r) {
return (4 / 3.0) * (22 / 7.0) * r * r * r;
}

double volume(double h, double r) {


return (22 / 7.0) * r * r * h;
}

double volume(double l, double b, double h) {


return l * b * h;
}

public static void main(String args[]) {


KboatVolume obj = new KboatVolume();
System.out.println("Sphere Volume = " +
obj.volume(6));
System.out.println("Cylinder Volume = " +
obj.volume(5, 3.5));
System.out.println("Cuboid Volume = " +
obj.volume(7.5, 3.5, 2));
}
}

Output

12/17
Question 8

Write a menu driven program to display the pattern as per user’s choice.

Pattern 1

ABCDE
ABCD
ABC
AB
A

Pattern 2

B
LL
UUU
EEEE

For an incorrect option, an appropriate error message should be displayed.

Answer

13/17
import java.util.Scanner;

public class KboatMenuPattern


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter 1 for pattern 1");
System.out.println("Enter 2 for Pattern 2");
System.out.print("Enter your choice: ");
int choice = in.nextInt();
switch (choice) {
case 1:
for (int i = 69; i >= 65; i--) {
for (int j = 65; j <= i; j++) {
System.out.print((char)j);
}
System.out.println();
}
break;

case 2:
String word = "BLUE";
int len = word.length();
for(int i = 0; i < len; i++) {
for(int j = 0; j <= i; j++) {
System.out.print(word.charAt(i));
}
System.out.println();
}
break;

default:
System.out.println("Incorrect choice");
break;

}
}
}

Output

14/17
Question 9

Write a program to accept name and total marks of N number of students in two single
subscript array name[] and totalmarks[].

Calculate and print:

15/17
1. The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
2. Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]

Answer

import java.util.Scanner;

public class KboatSDAMarks


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();

String name[] = new String[n];


int totalmarks[] = new int[n];
int grandTotal = 0;

for (int i = 0; i < n; i++) {


in.nextLine();
System.out.print("Enter name of student " + (i+1) + ": ");
name[i] = in.nextLine();
System.out.print("Enter total marks of student " + (i+1) + ": ");
totalmarks[i] = in.nextInt();
grandTotal += totalmarks[i];
}

double avg = grandTotal / (double)n;


System.out.println("Average = " + avg);

for (int i = 0; i < n; i++) {


System.out.println("Deviation for " + name[i] + " = "
+ (totalmarks[i] - avg));
}
}
}

Output

16/17
17/17
Solved 2019 Question Paper ICSE Class 10 Computer
Applications
knowledgeboat.com/learn/solved-icse-question-papers-computer-applications-class-10/solutions/6dNmB/year-
2019

2019

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

1/17
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 if switch-case

if else if can test for any Boolean expression switch-case can only test if the
like less than, greater than, equal to, not equal expression is equal to any of its case
to, etc. constants.

if else if can use different expression involving switch-case statement tests the same
unrelated variables in its different condition expression against a set of constant
expressions. 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

2/17
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 search Binary search

Linear search works on sorted and Binary search works on only sorted arrays.
unsorted arrays.

In Linear search, each element of the In Binary search, array is successively


array is checked against the target value divided into 2 halves and the target
until the element is found or end of the element is searched either in the first half
array is reached. 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

3/17
(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:

i Output Remark

5 1st Iteration — As i % 2 gives 1 so condition is true and continue


statement is executed. Nothing is printed in this iteration.

4 4 2nd Iteration — i % 2 is 0 so condition is false. Print statement prints 4


(current value of i) in this iteration.

3 4 3rd Iteration — i % 2 is 1 so continue statement is executed and nothing


is printed in this iteration.

2 42 4th Iteration — i % 2 is 0. Print statement prints 2 (current value of i) in


this iteration.

1 42 5th Iteration — i % 2 is 1 so continue statement is executed and nothing is


printed in this iteration.

0 42 As 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

4/17
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

5/17
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

Cost Discount (in percentage)

Less than or equal to ₹10000 5%

More than ₹10000 and less than or equal to ₹20000 10%

More than ₹20000 and less than or equal to ₹35000 15%

More than ₹35000 20%

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

6/17
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();

7/17
}
}

Output

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

Letters Unicode

A 65

B 66

. .

. .

. .

Z 90

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

1
12
123
1234
12345

8/17
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

9/17
10/17
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

11/17
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

12/17
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

13/17
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

14/17
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

15/17
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

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

16/17
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

17/17

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy