ICSE 10 Sample Paper 1 Ans
ICSE 10 Sample Paper 1 Ans
(Theory)
(Two hours)
Answers to this Paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers.
1
Ans: 10
8
Explanation
a = 9;
a++; // a = 10
SOP (a) // Prints 10
a -= a-- - --a;
a = 10 – (10 – 8)
a = 10 -2 = 8
SOP (a) // Prints 8
Ans.
X = 9.0 Working: 9.0 + (-4.0) + 4.0 = 9.0
Y = 4.0 Working Math.abs(Math.round(-4.4)) = 4.0
a. In the program given below, state the name and the value of the :
i. method argument or argument variable
ii. local variable
iii. class variable
iv. 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);
}
} [2]
Ans.
i. Method argument or argument variable is: n
ii. The class variable is : x
iii. The local variable is: a
iv. The instance variable is: y
Ans.
My Friends are
Ronit Nihir and Ananya too.
3
return a*a;
}
int Sum(int a, int b){ // 2nd overloaded function with two arguments
return ((a*a) + (b*b));
}
}
Character.toLowerCase() Character.isDigit()
It is used to convert a string into lower case It returns true if character argument is a
form (Small letters). digit, otherwise returns false.
Example: Example:
char ch= 'd'; Char c=‟b‟;
char st= Character.toUpperCase( ch ); boolean st1= Character.isDigit(ch);
Question 3.
a. Explain the statements (i) and (ii) from the following code.
char x ='a';
(i) x+= 3; // why will this run?
(ii) x= x +3; //why will this gives compile time error? [2]
Ans.
(i) Because x += 3; is equivalent to x = (char) (x+3); // here (char) is type casting
(ii) Where x +3 is default to int operation, assign an int to char must be type cast.
4
Pure Function Impure Function
It does not modify the arguments It modifies the state of arguments
received OR
Relies only on parameters passed to it. Refers to variables outside of method.
e.g. e.g.
public class TestMax { public class TestMax {
/* Return the max between two int */ highestNo = 23;
public static int max(int n1, int n2) public static int max(int n1, int n2)
{ …; {
Return n1; …
} if (n1 < highestNo)
result = highestNo;
…}
e.g
Class Simply {
int x, y;
// Constructor
Simply (int x, int y)
{
this.x = x;
this.y = y;
}
}
”WH”+”EAT”= “WHEAT”)
5
ii. Cheek if the second character of a string str is in uppercase. [2]
Ans.
i. char ch = wd.charAt(wt.length() -2);
ii. if (Character.isUpperCase(str.charAt(1))) OR
if (str.charAt(1)> 'A ' && str.charAt(1) <= „z‟)
g. 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; [2]
Ans.
The statement 1 has two errors: the square brackets „[ ]' is required as "int[ ] a" or "int a[ ]”.
Also, the size of the array 5 should be within the „[ ]‟ bracket instead of ( ).
The statement 2 has one error. The loop should be 0 to 4 i.e. for( int i=0; i< 5; i++) or for( int
i= 0; i <5;i++)
Correct program code
int a[ ]= new int[ 5 ];
for(int i= 0; i <5; i++)
a[i]= i;;
i. If String n1 = "99"; and String n2="100”; Give the output of the following:
i. String st= n1+n2; System.out.println (st) ;
ii. System.out.println( n1.charAt( 1 ));
iii. System.out.println( n2 + n1);
iv. System.out.printlnt (n1+ “ ”+n2); [2]
Ans.
i. 99100
ii. 9
iii. 10099
iv. 99 100
( )
j) Write an expression for [2]
√
Ans.
Math.pow ((x+y), 2) / (Math.cbrt(3)+y)
6
SECTION B (60 Marks)
Attempt any four questions from this Section.
The answers in this Section should consist of the Programs in either Blue J environment or any
program environment with Java as the base. Each program should be written using Variable
descriptions/Mnemonic Codes such that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required .
Question 4.
Data members:
int Epan : To store personal account number
Instance variables
String Ename : To store name.
double taxincome : To store annual taxable income.
double tax : To store tax that is calculated.
Member functions:
inputData () : Store the pan number, name, taxable income.
cal() : Calculate tax of an employee.
display() :Output details of an employee.
Write a program to compute the tax according to the given conditions and display the output as per
given format.
Output:
Pan Number Name Tax-Income Tax
……………… ……………… ……………… ………………
……………… ……………… ……………… ………………
[15]
import java.io.*;
public class Employee
{
int Epan;
double inc, tax;
String Ename;
7
public void inputData()throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter the Pan Number");
Epan= Integer.parseInt(in.readLine());
System.out.println("Enter the name of the employee");
Ename=in.readLine();
System.out.println(" Enter the Taxable Income");
inc= Integer.parseInt(in.readLine());
}
public void cal()
{
if(inc<= 100000)
tax= 0;
else if(inc<= 150000)
tax=10* (inc-100000)/100;
else if(inc<= 250000)
tax= 5000+20*(inc-150000)/100;
else
tax= 25000+30* (inc-250000)/100;
}
public void display()
{
System.out.println("Pan Number\tName\tTaxablelncome\tTax ");
System.out.println(Epan+"\t" +Ename+"\t" + inc+"\t" +tax);
}
}
Question 5.
Write a program in Java to store 10 numbers each in two different Single Dimensional Array. Now,
merge the numbers of both the arrays in a Single Dimensional Array. Display the elements of merged
array
Sample Input:
a[0] a[1] a[2] a[3] a[4]
10 21 44 45 32
8
b[0] b[1] b[2] b[3] b[4]
35 56 27 91 64
Sample Output:
The list after merging of two arrays:
c[0] c[1] c[2] c[3] c[4]
10 21 44 45 32
import java.io.*;
public class MergeArray
{
public static void main(String args[])throws IOException
{
int a[]=new int[5];
int b[]= new int[5];
int c[]= new int[10];
int k=0, i;
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter 5 numbers in the first array: ");
for(i=0;i<5; i++)
{
a[i]=Integer.parseInt(in.readLine());
}
System.out.println("Enter 5 numbers in the second array: ");
for(i= 0;i<5; i++)
{
b[i]= Integer.parseInt(in.readLine());
}
for(i=0; i<5; i++)
{
c[i]=a[i];
}
for(i= 5; i<10; i++ )
{
c[i]=b[k];
k= k+1;
}
System.out.println("The list after merging of two arrays");
for(i=0;i<10; i++)
{
System.out.println(c[i]+" ");
}
9
}
}
Question 6.
Write a class to design the given function to perform the the related tasks:
double volume1( double side )- to find and return volume of cube using (side*side*side).
double volume2( double l, double b, double h)- to find and return volume of cuboid
using:(length*breadth*height).
double volume3( double r )- to find and return volume of cylinder using: ((4/3)πr^3) [15]
Ans.
import java.util.Scanner;
public class Fuctions01
{
public double volume1(double s)
{
return (s*s*s);
}
public double volume2(double l, double b, double h)
{
return (l*b*h);
}
public double volume3(double r)
{
return ((4/3)*3.14*r);
}
}
Question 7.
10
Using the switch statement, write a menu driven program for the following:
i. To print the Floyd‟s triangle [Given below]
1
23
456
7 8 9 10
11 12 13 14 15
import java.util.Scanner;
public class ICSE_Triangle
{
public static void main(String[] args)
{
System.out.print("(1)To print the Floyd‟s triangle:");
System.out.println("\n1 \n12 \n123 \n1234 \n12345");
System.out.print("(2)To display the following pattern:");
System.out.println("\nI \nIC \nICS \nICSE");
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice)
{
case 1:
System.out.println("Enter the number of rows: ");
int n = scanner.nextInt();
int currentNumber = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(currentNumber + " ");
currentNumber++;
}
System.out.println();
}
break;
case 2:
String word = "ICSE";
for (int i = 0; i < word.length(); i++)
{
for (int j = 0; j <= i; j++)
{
11
System.out.print(word.charAt(j) + " ");
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");
break;
}
}
}
Question 8.
Write a program in java to store the numbers in 3 x 3 matrix in Double Dimensional Array. Display
the sus of:
i. left diagonal elements
ii. right diagonal elements
iii. difference between the sum of left and right diagonal elements [15]
Ans.
import java.io.*;
public class LeftRight
{
public static void main(String args[ ])throws IOException
{
int i, j,ld=0,rd=0,k=2;
int num[ ][ ]=new int[3][3];
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the numbers in the 3 x 3 matrix: ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
num[i][j] =Integer.parseInt(in.readLine());
}
12
}
System.out.println ("The elements of 3 x 3 matrix are:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(num[i][j]+" ");
}
System.out.println ();
}
for(i=0;i<3;i++)
{
ld=ld+num[i][i];
}
for(i=0;i<3;i++)
{
rd=rd+num[i][k];
k=k-1;
}
System.out.println("The sum left diagonal:"+ld);
System.out.println("The sum right diagonal:"+rd);
System.out.println("The diff. between left and right diagonal:"+(ld-rd));
}
}
Question 9.
Write a Java program to implement a class Strings with a following method named swapPairs that
accents a String as a parameter and returns that String with each pair of adjacent letters reversed. If
the String has on odd number of letters, the last letter is unchanged.
For example,
the call swapPairs("forget") should return "ofgrte" and the call swapPairs("hello there") should return
"ehll ohtree".
The class also has method main() that accepts a string and calls swapPairs() method to swap pairs of
characters in the passed string. [15]
Ans.
import java.util.Scanner;
13
public class Strings
{
String swap(String str)
{
int len = str.length();
int last = 0;
if (len % 2 != 0) // if len is even
last = len - 1 ;
else
last = len - 2 ;
StringBuffer sb = new StringBuffer(str);
char ch1,ch2 ;
for (int i =0 ; i< last ; i += 2)
{
ch1 = sb.charAt(i) ;
ch2 = sb.charAt(i + 1) ;
sb.setCharAt(i, ch2);
sb.setCharAt(i + 1, ch1) ;
}
return sb.toString();
}
public static void main(String[ ] args)
{
Scanner in = new Scanner (System.in) ;
System.out.println("Enter a string : ") ;
String inputStr = in.nextLine ();
Strings sobject = new Strings(); // create object of class
String outStr = sobject.swap(inputStr) ;
System.out.println("Output String after swapping characters :");
System.out.println(outStr);
}
}
Variable Description table:
Variable Name Data type/ Variable Purpose
method
len int To store length of String
last int To store last index of String
ch1, ch2 char To store and swap characters
i,j,k int Loop variable
14