ICSE Class 10 Computer Applications Sample Question Paper 2 with Answers
Section – A [40 Marks]
Attempt all questions
Question 1
(a) State one difference between primitive literals float and double.
(b) What is an infinite loop. Write a statement for infinite loop.
(c) Arrange the operators in the order of higher precedence.
(1)++ (2)&& (3)>= (4)%
(d) What is final variable and static variable?
(e) What is number of bytes char occupies. Write its range also.
Answer:
(a)
Float | Double |
Float occupies 4 bytes in memory | Double occupies 8 bytes in memory |
(b) An infinite loop occurs when there is no end to the iteration and loop continues to run indefinitely.
E.g. for
System.out.println(“10”);
(c) ++, % >=, &&
(d) When any variable is declared using final keyword it makes the value of that variable as constant. It can’t be changed throughout the program.
E.g. final int temp = 90;
Static variable are those which can be used only by static methods. It has only single copy throughout the class.
(e) 2 bytes and its range is 0 to 65,536
Question 2
(a) What is the difference between keyword parse and function valueOf( ). Give example of each.
Answer:
Parse | ValueOf |
It converts a variable from string data type to another. E.g. String a = “12”; int b = Integer.parselnt(a); |
It converts only from string to int. E.g. string a = “12”; Int b = Integer.valueOf(a); |
(b) Write a program code to accept a character input and check whether its digit using its ASCII code. Print character using suitable message.
Answer:
class abc { public void main( ) { scanner sc = new scanner(system.in); System.out.println("Enter the character to be checked"); char ch = sc.next( ). charAt(0); if(ch >=91 && ch <= 97) System.out.println("Digit is "+ch); else System.out.println("lts not a digit"); } }
(c) What do you mean by block. Give one example.
Answer:
Block is a set of statements in a program.
Eg
{
System.out.printlnC’example of block statement”);
System.out.println(“End of block statement”);
}
(d) State the difference between entry controlled loop and exit controlled loop.
Answer:
Entry Controlled Loop | Exit Controlled Loop |
Here condition is checked before entering the loop. Eg. while(i<3) { //some statements } |
Here condition is checked after entering the loop. First time entering in the loop is must. E.g. { }while (i< 3); |
(e) Write two advantages of using function in the program. And explain role of void in declaring functions?
Answer:
Advantages:
It makes the program divides into multiple modules.
Each module is independent in executing its dedicated task.
It helps in reusability of the code once written.
void makes sure that function doesn’t return anything.
Question 3
(a) What do you mean by function overloading? Explain with example.
Answer:
Function overloading is called when function with the same name is used multiple times with different arguments.
Example:
class abc { public: area(int a); area(int a, int b); area(int a, int b, float c); }
(b) What is this keyword? Also discuss the significance of it.
Answer:
- This keyword is used as a reference to created object for calling its methods or member functions.
- It differentiates between instance variables from the local variables when they have the same names.
(c) Attempt the following
(i) State the two features of a constructor.
Answer:
Constructor is function which has the same name as that of class without return type. It is called whenever the object is created for the class.
(ii) Write a valid java program code to print the following array in matrix form with 2 rows and 2 columns.
int mat[ ][ ] = {{2,6},{10,20}};
Answer:
for(int i =0;i<=2;i++) { for(int j =0;j<=2;j++) System.out.print(mat[i][j]); System.out.println( ); }
(iii) State the total size in bytes of the array a[4] of char data type and p[4] of float data type.
Answer:
char a[4] it occupies 8 bytes.
float p[4] it occupies 16 bytes.
(iv) String abc = “helloR”;
StringBuffer str = new StringBuffer(abc);
int num = str.capacity( );
what will variable num stores the value?
Answer:
22
(v) StringBuffer s1 = new StringBufferC’Robot”);
String s2 = s1 .reverse( );
System.out.println(“s2 =” +s2);
System.out.println(“s1 =” +s1);
Answer:
toboR
toboR
(d) Write a java statement for finding and displaying the position of last space in string’str’.
Answer:
String str = “Blank”;
int a = str.lastlndexOf(‘ ‘));
System.out.println(a +” is the last position of”);
(e) Which one of the following returns the corresponding primitive data type object from string object?
(i) Integer
(ii) readLine( )
(iii) valueOf( )
(iv) endsWith( )
Answer:
(i) int
(ii) String
(iii) int
(iv) boolean
(f) What do you mean by Abstraction and information hiding in java?
Answer:
Data abstraction is the act of representing the essential features of the program without involving in its complexity.
Information hiding in java means data members which can’t be accessed directly by objects instead it has access via its member functions.
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
Write a program to input three sides of a triangle (s1, s2, s3). Using switch case print whether a triangle is Equilateral, Isosceles, Right angled triangle or scalene. The program should be used with menu and switch-case.
Answer:
import java.util.*; class Triangle { public static void main( ) { Scanner sc = new Scanner(System.in); System.out.println("Enter 3 sides of triangle "); double s1 = sc.nextDouble( ); double s2 = sc.nextDouble( ); double s3 = sc.nextDouble( ); char ch ='0'; double sq 1 = si* si; double sq2 = s2*s2; double sq3 = s3 * s3; double sum1 = sql + sq2; double sum2 = sq2 + sq3; double sum3 = sql + sq3; if(s1 == s2 &&s2 == s3 ) ch = 'E'; if(s1 == s2 || s2 == s3 || s1 == s3) ch = I; if(sum1 == sq3 || sum2 == sq 1 || sum3 == sq2) ch = 'R'; if(s1 != s2 && s2!=s3) ch = 'S'; switch(ch) { case 'E': System.out.println("Equilateral triangle"); break; case T: System.out.println("lsoscless triangle"); break; case 'R': System.out.printlnfRight triangle"); break; case 'S': System.out.printlnC'Scalene triangle"); break; default: break; } } }
Question 5
Write a program to find the sum of the following series:
\(x+\frac{x^{2}}{2 !}+\frac{x^{2}}{3 !}+\frac{x^{4}}{4 !}+\ldots . \text { nterms }\)
Answer:
import java.util.*; class series { public static void main( ) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number and number of terms"); int x = sc.nextlnt( ); int n = sc.nextlnt( ); int a = 1; int f; double sum = 0.0; forfint i =1; i<= n; i++) { f = 1; for(int j = 1; j<=i;j++) f = f*j; sum = sum+(Math.pow(x,a)/f); a++; } System.out.printlnC'sum: "+sum); } }
Question 6
A number is said to be NEON number if sum of digits of square of a number is equal t:o the number itself.
Example:
INPUT N = 9, Output Square: 81 (where 8 + 1 = 9 so 9 is NEON number)
Write a program to find such numbers between 10 and 10000.
Answer:
import java.util.*; class Neon { public static void main( ) { int a = 10; for(int i =10;i<=10000; i++) { intal =a; long sq = a1*a1; int sum =0; while(sq >=0) { int k = (int)sq % 10; sum = sum + k; sq = sq/10; if(sum == a) System.out.println(a); a++, } } }
Question 7
Write a program to perform binary search on the list of 10 integers entered by user in ascending order to search for an element input by user, if it’s found display the element along with its position else display the message “search element not found”.
Answer:
import java.util.*; class binsearch { public static void main( ) { Scanner sc = new Scanner(System.in); System.out.priintlnfEnter the 10 no.s in ascending order to be put in the array"); int[ ] a = new int[10]; for(int i = 0; i< 10; i++) a[i] = sc.nextlnt( ); System.out.println('Enter the no. to be searched in the array"); int n = sc.nextlnt( ); int start =0,pos=0; int last =a.length - 1; int mid = (start + last) / 2; int found = 0; while(start <= last) { if(n == a[mid]) { pos = mid; found = 1; break; } if(n < a[mid]) mid = last - 1; if(n > a[mid]) mid = start + 1; } if(found == 1) System.out.println(n+" found at position "+pos); else System.out.println(n+" not found"); } }
Question 8
Write a program to accept a word and convert into lowercase if it is in uppercase and display the new word by replacing the VOWELS with the character following it.
ex: Sample intput: VOWEL
Sample output: vpwfi
Answer:
import java.util.*; class strlol { public static void main( ) { Scanner sc = new Scanner(System.in); Systenn.out.println("Enter a word"); String strl = sc.next( ); String str = strl .toLowerCase( ); String word = " "; for(int i = 0; i <- str.length( )-1; i++) { char ch = str.charAt(i); if (ch != 'a' && ch !='e' && ch != T && ch != 'o' && ch!='u') word = word + ch; if(ch=='a' || ch == 'e'|| ch == 'i' || ch == 'o' || ch == 'u') { ch ++; word = word + ch; } } System.out.println(word); } }
Question 9
Write a program in java to print the following output.
Answer:
import java.util.*; class pattern { public static void main() { for(int i = 5; i>= 1; i- -) { int a = i-1; for(int k = 1; k <= 5-i; k++) System.out.print(" "); for(int j = 1;j<= i;j++) { System.out.println(j+" "); if(a > 0) System.out.println("*"); a- -; } System.out.println ( ); } } }
Variable | Data Type | Description |
sq1, sq2, sq3 | double | To find squares of each side |
ch | char | To store the type of triangle. |
x, n | int | Number and number of terms. |
f | Int | Factorial storing |
sum | double | To store sum of series. |
sum | Int | To store sum of digits of neon number. |
a[ ] | int | To store integers in ascending order. |
n | int | Element to be searched. |
start,last mid | int | Positions of index of array |
found | int | Flag to check element is found or not. |
strl | string | For storing string. |
ch | char | To take out each character of string. |
word | String | For storing the required string. |
a | int | Number of rows. |