You are on page 1of 6

ICSESOLVEDQUESTIONPAPER(2007)

2007
SECTION A (40 Marks)
Attempt all questions
Question 1 [10]
(a) Name two types of Java programs.
(b) Define Instance Variable. Give an example of the same.
(c) Differentiate between Binary Search and Linear Search.
(d) Assign the value of pie (i.e. 3.142) to a variable with requisite data type.
(e) Explain with an example the if-else-if construct.
Question 2 [10]
(a) Differentiate between Formal Parameter and Actual Parameter.
(b) Why do we need a constructor as a class member?
(c) Explain the term type casting.
(d) Name the following:i.
A package that is invoked by default.
ii.

A key word, to use the classes defined in a package.

(e) Name the class that is used for different mathematical functions. Give an example of a
mathematical function.
Question 3
(a) State the difference between = and = =. [2]
(b) Write an equivalent Java syntax for the following expression:- a = 0.05 2y 3 / x y [2]
(c) Rewrite the following using Ternary operator
if (income < = 10000 )
tax = 0 ;
else
tax = 12 ; [2]
(d) Write a statement for each of the following:i.
Store a number 275 as a String
ii.

Convert the string to a numeric value

iii.

Add it to the existing total of 1000 to update the total. [3]

(e) (i) What is the role of the keyword void in declaring functions?
(ii) If a function contains several return statements, how many of them will be executed?
(iii) Which OOP principle implements function overloading? [3]
(f) What is the output of the following:i.
System.out.println ("four :" + 4 + 2);
System.out.println (" four : "+(2+2)); [2]
ii.

String S1 = "Hi";
String S2 = "Hi"; String S3 = "there";
String S4 = "HI";
System.out.println(S1 + "equals" + S2 + "" + S1.equals(S2));
System.out.println(S1 + "equals" + S3 + "" + S1 .equals(S3));

System.out.println(S1 + "equals" + S4 + "" + S1 .equals(S4));


System.out.println(S1 + "EqualIgnoreCase" +S4 + "" + S1.EqualIgnoreCase(S4)); [4]
i.
ii.

(g) Evaluate the following expressions, if the values of the variables are a = 2, b=3 and c=9
a (b++) * ( c)
a * (++b) % c [2]
SECTION B (60 Marks)
Question 4
Define a class salary described as below:-

Data Members
:

Name, Address, Phone, Subject Specialization,


Monthly
Salary, Income Tax.

Member methods
:

(i) To accept the details of a teacher including the


monthly
salary.
(ii) To display the details of the teacher.
(iii) To compute the annual Income Tax as 5% of the
annual
salary above Rs.1,75,000/-.

Write a main method to create object of a class and call the above member method. [15]
Question 5
Write a program to compute and display the sum of the following series:- [15]

1+2
12

1+2+3
123

+.......+

1 + 2 + 3 + 4....n
1 2 3 4....n

Question 6
Write a program to initialize the given data in an array and find the minimum and maximum
values along with the sum of the given elements.
Numbers : 2 5 4 l 3
Output : Minimum value : l
Maximum value : 5
Sum of the elements : [15]
Question 7
Write a program to enter a sentence from the keyboard and count the number of times a
particular word occurs in it. Display the frequency of the search word.
Example:
INPUT:
Enter a sentence : the quick brown fox jumps over the lazy dog.
Enter a word to be searched : the
OUTPUT:
Searched word occurs : 2 times. [15]
Question 8

Using a switch statement, write a menu driven program to convert a given temperature from
Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate error message
should be displayed. [15]

(HINT

5/9

(F 32)

and

1.8

C + 32

Question 9
Write a program using a method Palin( ), to check whether a string is a Palindrome or not. A
Palindrome is a string that reads the same from left to right and vice versa.
E.g. MADAM, ARORA, ABBA, etc. [15]

Solution of 2007 Paper:


Q. 4:
class salary
{
String name,phone,add,sub;
int salary,tax;
void input(String n, String p, String a, String s, int sa)
{
name=n;
phone=p;
add=a;
sub=s;
sal=sa;
}
void compute()
{
if(sal*12>175000)
tax=(sal*12)-175000*5/100;
}
void display()
{
System.out.println(name);
System.out.println(phone);
System.out.println(add);
System.out.println(sub);
System.out.println(sal);
}
public static void main(String args[])
{
salary obj=new salary();
obj.input(Tarun,9876543210,mahanagar,history,10000);
obj.compute();
obj.display();
}
}

Q.5:
import java.io.*;
class series
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
int n,p=1,s=0,sum=0;
System.out.println(enter terms);
n=Integer.parseInt(br.readLine();
for(int i=2;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
p=p*j;
s=s+j;
}
sum=sum+s/p;
}
System.out.println(sum);
}
}
Q.6
import java.io.*;
class maxmin
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
int a[]={2,5,4,1,3};
int max=0,min=a[0],sum=0;
for(int i=0;i<5;i++)
{
sum=sum+a[i];
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
System.out.println(min);
System.out.println(max);
System.out.println(sum);
}
}
Q.7:

import java.io.*;
class wordfreq
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s,wrd,w=;
int len,f=0;
System.out.println(enter a sentence);
s=br.readLine();
System.out.println(enter a word);
wrd=br.readLine();
len=s.length();
for(int i=0;i<len;i++)
{
if(s.charAt(i)== ||s.charAt(i==.)
{
if(w.equals(wrd))
f++;
w=;
}
w=w+s.charAt(i);
}
System.out.println(f);
}
}
Q.8:
import java.io.*;
class cel
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int ch,tmp;
System.out.println(" 1. Celsius to Fahrenheit");
System.out.println(" 2. Fahrenheit to Celsius");
System.out.println(" UR CHOICE ");
ch=Integer.parseInt(br.readLine());
System.out.println("Enter temperature");
tmp=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.print(1.8*tmp+32);
break;
case 2:

System.out.print((5/9)*(tmp-32));
break;
default:
System.out.print(" Invalid Input ");
break;
}
}
}
Q.9:
import java.io.*;
class palindrome
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println(enter a string);
str=br.readLine();
palin(str);
}
static void palin(String s)
{
String s2=;
int len=s.length();
for(int i=--len;i>=0;i--)//this loop stores reverse string to str2
{
s2+=s.charAt(i);
}
if(s.equals(s2))
System.out.print("Palindrome");
else
System.out.print("Not Palindrome");
}
}

You might also like