ICSE Class 10 Computer Applications Sample Question Paper 9 with Answers
Section- A (40 Marks)
Attempt all questions
Question 1
(a) What is the return of following function.
(i) equals( )
(ii) rint( ).
(b) What do you mean by compound statement. When do you need it.
(c) Explain difference between character constant and string constant.
(d) State any two features of constructor.
(e) Define abstraction.
Answer:
(a) (i) boolean
(ii) double
(b) A set or a block of statement in a program is called compound statement. It can be used to divide the program into segments and organise the data accordingly.
(c)
Character Constant | String Constant |
Enclosed in single quotes E.g. ‘A’, ‘e’ | Enclosed in double quotes E.g. “hello”, “1 like JAVA” |
(d) It has same name as that of class. It has no return type.
(e) Abstraction is the act of representing the essential features of a program without involving in its complexity.
Question 2
(a) Explain the term object using example?
(b) What is the wrapper class. Justify with example?
(c) State the purpose of new operator?
(d) Write java expression for
\(\sin x+\sqrt[2]{a x^{2}-b x+c}\)
Answer:
(a) Object is an identifiable entity with some particular characteristics and behaviour.
E.g.TV, characteristics: Big, small etc.
Behaviour: Show different channels, off/on etc.
(b) The class which helps in converting primitive data types to object type is called wrapper class. Eg. Character, Integer etc.
(c) The ‘new’ keyword supports instantiation. It allocates memory for the newly created object.
(d) double z = Math.sin(x)+Math.sqrt(a*x*x + b*x + c);.
(e) class lol
Question 3
(a) Explain the concept of constructor overloading with example.
(b) Differentiate between equals( ) and compareTo( ).
(c) Attempt the following:
(i) Differentiate between call by value and call by reference.
(ii) What is an identifier. Give example
(iii) Name the package that contains the scanner class. Which unit or class gets called when object is created.
(iv) What is meant by encapsulation.
(v) What is meant by inheritance.
(vi) char a[ ]={‘a’,’b’,,c’}; System.out.println(a); What will be the output.
(vii) char a[ ]={‘a’,’b’,’c’}; System.out.println(a[1]++); System.out. println(++a[1]);
(viii) inta[ ]={1,2,3};System.out.println(a[1]++);System.out.println(++a[1]);
Answer:
(a) Same as above.
(b)
Equals( ) | CompareTo( ) |
It returns boolean value | It returns integer value |
Compares the whole string at once. | It compares the ASCII values of each character of the string. |
(c) (i)
Call by Value | Call by Reference |
Actual parameters are copied into the formal parameters. | Actual parameters alias are created in the formal parameters. |
Changes made by the formal parameters is not reflected back to the actual parameter | Changes made by the formal parameter directly affect the actual parameters. |
(ii) Identifiers are those quantities which change their values during the execution of the program. E.g. Int a, b;
(iii) java.util and constructor.
(iv) Encapsulation: Wrapping of data and its associated functions into a single unit.
(v) Inheritance is the method of inheriting the properties of one class from another class. The class which derives its own properties is called base class and the class which derives the properties of another class is called sub class.
(vi) Address of array a[ ]
(vii) b d
(viii) 2
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 print the sum of prime digits from given number.
E.g. 134667
Output: 1+3+7=11
Answer:
import java.util.*; class Main { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); System.out.println("enter the number:"); int a = sc.nextlnt( ); int a 1 = a; int sum = 0; while (a 11=0) { int count = 0; int k = a1%10; for(int i=1; i<=k; i++) { if(k%i==0) count++; } if(count==2) sum+=k; a 1 /=10; } System.out.println("sum = "+sum); }//end of main }//end of class
Question 5
Write a program to print the longest word from the sentence and print the number of characters of the longest word.
Answer:
import java.util.*; class Main { public static void main(String [ ] largs) { int count = 0; String temp; Scanner sc = new Scanner(System.in); System.out.println("Enter a sentence:"); String str = sc.nextLine( ), word =""; str - str+" "; for(int i = 0; i<str.length( ); i++) { char ch = str.charAt(i); if(ch=='') count++; } String a[ ] = new Stringfcount]; for(int i = 0; i<count;i++) { for(int j = 0;j< str.length( ); j++) { char ch = str.charAt(j); if(ch!='') word+=ch; else { a[i] =word; word =" } } } for(int i = 0;i<a.length; i++) { for(int j = 0;j<a.length-i-1;j++) { if(a[j].length() > a[j+1].length()) { temp = a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } System.out.printlnfLONGESTWORD: "+a[a.length-1]); System.out.println("No. of characters:"+a[a. length-1 ].length()); }//end of main }//end of class
Question 6
Write a program to find sum of negative numbers, sum of positive odd numbers and sum of positive even numbers entered by user and list terminates when user enters 0.
Answer:
import java.util class Main { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int sum = 0, sum1 = 0, sum2 = 0; System.out.println("Enter the number to calculate and 0 for exit:"); int n = sc.nextlnt( ); int a = n; while(a!=0) { if(a>0) { if(a%2 == 0) sum1+=a; else sum2+=a; } else { sum+=a; } System.out.println(''Enter the next number and 0 to exit:"); a = sc.nextlnt( ); } System.out.println("Positive even sum: "+suml+"\t"+"Positive odd sum:"+sum2+"\t"+"Negative sum:"+sum); } //end of main }//end of class
Question 7
Using switch case write a menu driven program to print the patterns.
(a)
0 0 0 0 0
2 2 2 2
6 6 6
12 12
2 0
(b)
X
Y Y
X X X
Y Y Y Y
X X X X X
Answer:
import java.util.*; class Main { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); System.out.println(''Enter the choice:"); intal = sc.nextlnt( ); switch(al) { case 1: inta = 0; int b = 2; for(int i =5;i>= 1;i—) { for(int j=1; j<=i;j++) System.out.print(a+" "); a+=b; b+=2; System.out.println( ); } break; case 2: for(int i =1; i<=5; i++) { for(int j=1;j<=i;j++) { if(j%2 != 0) System.out.printC'X"); else System.out.printC'Y''); } System.out.println( ); } break; default: System.out.println("lnvalid Choice"); } }//end of main }//end of class
Question 8
Write a program to find using binary search method from list of roll numbers entered by user in ascending order. If the search is successful print “you are selected to go” else print “Try next time”.
Answer:
import java.util.*; class Main { public static void main(String args[ ]) { int first, last, middle, n, search, array! ]; Scanner sc = new Scanner(System.in); System.out.println(''Enter total number of students"); n = sc.nextlntO; array = new int[n]; System.out.printlnC'Enter" + n + " integers"); for (int i = 0; i<n; i++) arrayti] = sc.nextlnt( ); System.out.printlnC'Enter value to find"); search = sc.nextlnt( ); first = 0; last = n - 1; middle = (first + last)/2; while(first <= last) { if (array[middle] < search) first = middle + 1; else if (array[middle] == search) { System.out.println(search + " you are selected to go " + (middle + 1) + "•"); break; } else last = middle - 1; middle = (first + last)/2; } if (first > last) System.out.println(search + " Try next timeAn"); }//end of main }//end of class
Question 9
Write a program to input sentence and print in the lowercase letters and replace all the words like “is” and “are” with “were” and “had” and “has” with “had”.
Answer:
import java.util.*; class Main { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the sentence:"); String str = sc.nextLine( ); String str1 = str.toLowerCaseQ; String word = strl +=" "; String str2 =" "; for(int i =0;i<str1 Jength(); i++) { char ch = strl .charAt(i); if(ch!='') word+=ch; else { if(word ,equals("is")) str2=str2+"were"+""; else if(word.equals("are")) str2=str2 + "had"+""; else if(word.equals("has")) str2=str2+"had" +""; else str2=str2+word+" "; word = } } System.out.println(str2); }//end of main }//end of class
Variable | Data Type | Description |
a | int | Store input integer from user |
a1,sum | int | For modifying digits and to calculate sum of digits |
str | String | Store input string from user |
ch | char | Store the character |
count | int | Count number of blank spaces |
word | String | To store new word |
temp | String | Temporary storage for swapping strings. |
a[ ] | String | Array of strings. |
n | int | Store integer from user |
a | int | For modifying value |
sum1,sum2,sum3 | int | Even number sum Positive odd sum Negative sum |
b | int | For printing even pattern |
‘j | int | For looping |
first last middle n search arrayj] | int | First last and middle are Index of array N is total number of elements Search is number to be searched in array. Array[ ] array of sorted roll numbers |
strl | String | Store lowercase word |
str2 | String | To store the modified sentence. |