In this page you will find the solution of ICSE computer papers solutions starting from 2007 to 2015. Students can get the solutions in many sites or solution books but I can ensure that this page will provide you the best solutions.
Year 2007
Name two types of Java programs: Two types of java programs are Applet and stand alone application. Applet is an internet program while stand alone application needs no net connection.
Define instance variable. Give an example: instance or object variables are those whose existence depends upon creation of object. Existence of instance variables comes into effect after creation of objects and for each object separate copies of instance variables will be created.
class A
{
int a;
void take()
{
statement (s)
}
}
In this above program, the variable 'a' is instance variable and if three objects of the class 'A' is created then for each copy of object, separate 'a' will be created.
Differentiate between binary search and linear search: 1. Binary search can search only unique values which is not the case with linear search.. Linear search can search both unique values as well as it can be used for category wise search.
2. Binary search has two preconditions which must be fulfilled and the preconditions are : the values must be in sorted order and middle location of the list can be accessed directly. No such preconditions are there for linear search.
2. Binary search has two preconditions which must be fulfilled and the preconditions are : the values must be in sorted order and middle location of the list can be accessed directly. No such preconditions are there for linear search.
Assign the value of pie (3.14) to a requisite data type: double db=3.14;
Explain with example the if..else..if construct
if (a>0)
System.out.println('Value is positive.");
else if (a<0 p="">System.out.println('Value is negative.");
else
System.out.println('Value is zero.");0>
if (a>0)
System.out.println('Value is positive.");
else if (a<0 p="">System.out.println('Value is negative.");
else
System.out.println('Value is zero.");0>
Differentiate between actual and formal parameter: actual arguments are those which are used in function calling statements and formal arguments are used at the argument zone in function definition
Why do we need a constructor a class member: Constructor execution is a must for creation of objects and that is the reason why we need a constructor.
Explain the tern type casting: Type casting is the technique of converting one type of data to other type. There are two types of type casting: explicit casting and implicit casting.
Name the following packages:
1. A package that is invoked by default: lang package which is contained within java package.
2. A keyword to use the classes defined in a package: import
Name of the class that is used for mathematical calculations. Give examples: Math class is used for different mathematical calculations in java. Math class is contained within lang package which is again contained within java package.
Example are: Math.pow(int,int), pow is a static function of Math class which takes two 'int' values as argument. The first argument is base and the second argument is exponent or power. The function returns the exponential value. If the first argument is 2 and the second argument is 3, the result would be 8.
Difference between = and ==: = is assignment operator which is used to assign the right side value on its left side variable like a=3. == is one of the six relational operators which is used to check two values for equality.
Write the equivalent java syntax a=(0.05-2y^3)/ (x-y):
double val=(0.05-2*y*y*y)/(x-y)
Convert the if else using ternary operator:
if (income<=10000)
tax=0;
else
tax=12;
Ans: tax=(income<=10000) ? 0 : 12;
Write a statement to store a number 275 as string: String str="275";
Convert the above string to a numeric value: int a = Integer.parseInt(str);
Add the value to total with initial value 1000: total=total+a;
Example are: Math.pow(int,int), pow is a static function of Math class which takes two 'int' values as argument. The first argument is base and the second argument is exponent or power. The function returns the exponential value. If the first argument is 2 and the second argument is 3, the result would be 8.
Difference between = and ==: = is assignment operator which is used to assign the right side value on its left side variable like a=3. == is one of the six relational operators which is used to check two values for equality.
Write the equivalent java syntax a=(0.05-2y^3)/ (x-y):
double val=(0.05-2*y*y*y)/(x-y)
Convert the if else using ternary operator:
if (income<=10000)
tax=0;
else
tax=12;
Ans: tax=(income<=10000) ? 0 : 12;
Write a statement to store a number 275 as string: String str="275";
Convert the above string to a numeric value: int a = Integer.parseInt(str);
Add the value to total with initial value 1000: total=total+a;
What is the role of the keyword void in function declaration: The keyword void in function declaration indicates that the function not return any value to the calling statement.
If a function has several return statements, how many of them will be executed: Only one
Which OOP principle implements function overloading: Polymorphism implements function overloading.
What will be the output of the following:
System.out.println("four:"+2 + 2): Ans four 22
System.out.println("four:"+(2 + 2)): Ans four 4
What is the output of the following:
String S1="Hi";
String S2="Hi";
String S3="there";
String S4="HI";
System.out.println(S1 + " equals" + S2 + "->"+ S1.equals(S2));If a function has several return statements, how many of them will be executed: Only one
Which OOP principle implements function overloading: Polymorphism implements function overloading.
What will be the output of the following:
System.out.println("four:"+2 + 2): Ans four 22
System.out.println("four:"+(2 + 2)): Ans four 4
What is the output of the following:
String S1="Hi";
String S2="Hi";
String S3="there";
String S4="HI";
Ans: Hi equals Hi -> true
System.out.println(S1 + " equals" + S3 + "->"+ S1.equals(S3));
Ans: Hi equals there -> false
System.out.println(S1 + " equals" + S4 + "->"+ S1.equals(S4));
Ans: Hi equals HI -> false
System.out.println(S1 + " EqualsIgnoreCase" + S4 + "->"+ S1.equalsIgnoreCase(S2));
Ans: Hi EqualsIgnoreCase HI -> true
Evaluate the following expression: a=2, b=3 and c=9
a-(b++)*(--c)
Ans: -22
a* (++b) % c
Ans: 8
a-(b++)*(--c)
Ans: -22
a* (++b) % c
Ans: 8
Programs
Program No 1: Define a class with the following members
Data Member: Name, Address, Phone, Subject Specialization, Monthly Salary, Income Tax
Method Members:
1. Accept details of the teacher including monthly salary
2. To display details of the teacher
3. To compute annual income tax at 5% of the annual salary above Rs. 1,75.000/-
import java.io.*;
class A
{
String name, address, phone, subject;
double salary, itax;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeDatas () throws Exception
{
System.out.println("Name:");
name=br.readLine();
System.out.println("Address:");
address=br.readLine();
System.out.println("Phone Number:");
phone=br.readLine();
System.out.println("Subject Specialization:");
subject=br.readLine();
System.out.println("Monthly Salary:");
salary=Double.parseDouble(br.readLine());
taxCompute();
}
private void taxCompute()
{
itax=salary*12;
itax=itax-175000;
if(itax >0)
itax=itax*5.0/100;
else
itax=0;
showDetails();
}
private void showDetails()
{
System.out.println("Name:"+name);
System.out.println("Address:"+address);
System.out.println("Phone Number:"+phone);
System.out.println("Subject Specialization:"+subject);
System.out.println("Monthly Salary:"+salary);
System.out.println("Income Tax:"+itax);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.takeDatas();
}
}
Program No 2: Write a program to display the sum:
1+2/1*2 + 1+2+3/1*2*3 + ....+ 1+2+3+..+n/1*2*3*...*n
import java.io.*;
class A
{
int i,j,n;
double s=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take () throws Exception
{
System.out.println("Enter value of 'n':");
n=Integer.parseInt(br.readLine());
compute();
}
private void compute()
{
int d1,d2;
for(i=1;i<=n;i++)
{
d1=1;
d2=1;
for(j=1;j<=i;j++)
{
d1=d1+j+1;
d2=d2+(j+1);
}
s=s+(double)d1/d2;
}
System.out.println("Sum of the series:"+s);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.take();
}
}
Program No 3: Initialise an array with five values like 2 5 4 1 3 and find the maximum, minimum values and the sum of the datas in the array
class A
{
int i,max,min,s=0;
int arr[]={2,5,4,1,3};
public void compute()
{
max=min=arr[0];
s=arr[0];
for(i=1;i< arr.length;i++)
{
if(arr[i]>max)
max=arr[i];
else if(arr[i]
min=arr[i];
s=s+arr[i];
}
System.out.println("Sum of the elements:"+s);
System.out.println("Maximum value:"+max);
System.out.println("Minimum value:"+min);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.compute();
}
}
Program no 4: Frequency of any word from a sentence, both word and sentence are entered by user.
import java.io.*;
class A
{
String s,s1,s2;
int i,count=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take () throws Exception
{
System.out.println("Enter the sentence:");
s1=br.readLine();
System.out.println("Enter the word to search:");
s2=br.readLine();
while(true)
{
i=s1.indexOf(" ");
if (i< 0)
break;
s=s1.substring(0,i);
s1=s1.substring(i+1);
if(s.equals(s2))
count++;
}
if(s1.equals(s2))
count++;
System.out.println("Frequency of the word "+s2 + ":"+count);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.take();
}
}
Program no 5: Using switch, a menu driven program to convert a given temparature from Celcius to Fahrenheit and vice versa. For incorrect input show appropriate error message.
C=5/9(F-32) and F=1.8*C+32
import java.io.*;
class A
{
double temp;
int choice;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take () throws Exception
{
System.out.println("Enter the temperature:");
temp=Double.parseDouble(br.readLine());
System.out.println("Enter the Choice (1 for Fahrenheit to Celsius and 2 for Selsius to Fahrenheit:");
choice=Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
temp=5.0/9*(temp-32);
System.out.println("Fahrenheit to Celsius value:"+temp);
break;
case 2:
temp=1.8*(temp+32);
System.out.println("Celsius to Fahrenheit value:"+temp);
break;
default:
System.out.println("Wrong Choice.");
}
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.take();
}
}
Program No 6: Program on palindrome checking
Click Here
Data Member: Name, Address, Phone, Subject Specialization, Monthly Salary, Income Tax
Method Members:
1. Accept details of the teacher including monthly salary
2. To display details of the teacher
3. To compute annual income tax at 5% of the annual salary above Rs. 1,75.000/-
import java.io.*;
class A
{
String name, address, phone, subject;
double salary, itax;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeDatas () throws Exception
{
System.out.println("Name:");
name=br.readLine();
System.out.println("Address:");
address=br.readLine();
System.out.println("Phone Number:");
phone=br.readLine();
System.out.println("Subject Specialization:");
subject=br.readLine();
System.out.println("Monthly Salary:");
salary=Double.parseDouble(br.readLine());
taxCompute();
}
private void taxCompute()
{
itax=salary*12;
itax=itax-175000;
if(itax >0)
itax=itax*5.0/100;
else
itax=0;
showDetails();
}
private void showDetails()
{
System.out.println("Name:"+name);
System.out.println("Address:"+address);
System.out.println("Phone Number:"+phone);
System.out.println("Subject Specialization:"+subject);
System.out.println("Monthly Salary:"+salary);
System.out.println("Income Tax:"+itax);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.takeDatas();
}
}
Program No 2: Write a program to display the sum:
1+2/1*2 + 1+2+3/1*2*3 + ....+ 1+2+3+..+n/1*2*3*...*n
import java.io.*;
class A
{
int i,j,n;
double s=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take () throws Exception
{
System.out.println("Enter value of 'n':");
n=Integer.parseInt(br.readLine());
compute();
}
private void compute()
{
int d1,d2;
for(i=1;i<=n;i++)
{
d1=1;
d2=1;
for(j=1;j<=i;j++)
{
d1=d1+j+1;
d2=d2+(j+1);
}
s=s+(double)d1/d2;
}
System.out.println("Sum of the series:"+s);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.take();
}
}
Program No 3: Initialise an array with five values like 2 5 4 1 3 and find the maximum, minimum values and the sum of the datas in the array
class A
{
int i,max,min,s=0;
int arr[]={2,5,4,1,3};
public void compute()
{
max=min=arr[0];
s=arr[0];
for(i=1;i< arr.length;i++)
{
if(arr[i]>max)
max=arr[i];
else if(arr[i]
min=arr[i];
s=s+arr[i];
}
System.out.println("Sum of the elements:"+s);
System.out.println("Maximum value:"+max);
System.out.println("Minimum value:"+min);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.compute();
}
}
Program no 4: Frequency of any word from a sentence, both word and sentence are entered by user.
import java.io.*;
class A
{
String s,s1,s2;
int i,count=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take () throws Exception
{
System.out.println("Enter the sentence:");
s1=br.readLine();
System.out.println("Enter the word to search:");
s2=br.readLine();
while(true)
{
i=s1.indexOf(" ");
if (i< 0)
break;
s=s1.substring(0,i);
s1=s1.substring(i+1);
if(s.equals(s2))
count++;
}
if(s1.equals(s2))
count++;
System.out.println("Frequency of the word "+s2 + ":"+count);
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.take();
}
}
Program no 5: Using switch, a menu driven program to convert a given temparature from Celcius to Fahrenheit and vice versa. For incorrect input show appropriate error message.
C=5/9(F-32) and F=1.8*C+32
import java.io.*;
class A
{
double temp;
int choice;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take () throws Exception
{
System.out.println("Enter the temperature:");
temp=Double.parseDouble(br.readLine());
System.out.println("Enter the Choice (1 for Fahrenheit to Celsius and 2 for Selsius to Fahrenheit:");
choice=Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
temp=5.0/9*(temp-32);
System.out.println("Fahrenheit to Celsius value:"+temp);
break;
case 2:
temp=1.8*(temp+32);
System.out.println("Celsius to Fahrenheit value:"+temp);
break;
default:
System.out.println("Wrong Choice.");
}
}
public static void main(String args[]) throws Exception
{
A object=new A();
object.take();
}
}
Program No 6: Program on palindrome checking
Click Here
Solved Papers from 2008 to 2015 coming soon.........
No comments:
Post a Comment