ICSE Class 9 Computer Applications Sample Question Paper 2 with Answers
Section – A
(Attempt all questions)
Question 1.
(a) Write two differences between Object Oriented Programming and Procedure Oriented Programming.
(b) Define abstraction with an example.
(c) What is copyright and what is trademark ?
(d) What are Java Applets ?
(e) What are spams ?
Answer:
Follows bottom-up approach
More secure as having data hiding feature
(a) OOP : Follows bottom-up approach
More secure as having data hiding feature
POP : Follows top-down approach
Less secure as there is no way of data hiding
(b) Any representation of data in which the implementation details are hidden is known as data abstraction.
For example, a person may know how to drive a car but may not know how to repair it.
(c) Copyright – It gives the right to the creator that no one can copy the same. However, someone can do the whole thing from the beginning keeping the basic idea same. Copyrighted items have a symbol of ©.
Trademark – It is a distinct name that is used for some kind of goods or services. Symbol of trademark is-©.
(d) A Java Applet is a small and efficient Java program, which is used for internet programming.
(e) These are bulk e-mails that are sent to people generally for advertising, phishing etc. In some cases, spam may consume a lot of memory space.
Question 2.
(a) Write two differences between if else and switch-case constructs.
(b) Write two features of a constructor.
(c) What are increment and decrement operators ?
(d) What are comments? Give example.
(e) What is ternary operator?
Answer:
(a) if else : All relational operators can be used.
All data-types are allowed.
Multiple conditions can be connected by using logical operators.
switch-case : Only comparison of equality operator can be used.
Only integer type (byte, short, int, long) and char type data can be used.
Multiple conditions cannot be connected by using logical operators.
(b) Has the same name as the class and no return type.
Invoked directly when object is created.
(c) These operators are used to increment / decrement the value of a variable by 1.
a = 5; a++ ; / / value of a becomes 6
(d) Comments are statements that are not executed by the compiler/interpreter. They are used to provide information about parts of the code.
Single line comment / /
Multiple line comment /* ………. * /
(e) It is a single line conditional operator.
Syntax : result = Cond ? true : false;
Example : r = (a>b)?a : b;
Question 3.
Answer with respect to given code :
(a) The given code has some errors. Rewrite the code correctly and underline the changes made
Switch (m)
{
case 8 : System.out.piint [88];
break;
default: System.out.print [100];
}
Answer:
(a)
switch (m) { case 8 : System.out.print(88); break; default : System.out.print(100); }
(b) Identify the error, if any, in the following code snippet:
for ( c ==25, c < 20 , c – -)
Answer:
for ( c =25; c > 20; c – – )
(c) Identify the error, if any, in the following code snippet:
for (q = = 1; q <= 100 ; q = = q + 10 )
Answer:
for (q = 1; q <= 100; q = q + 10 )
(d) What are the components of a for loop ?
Answer:
initialization
condition test
update variable
(e) What is the role of break statement in a loop ? Show a code example.
Answer:
When a break statement is encountered inside a loop, it is immediately terminated and the control comes out of the loop block and resumes at the next statement following the loop.
for(k=1;k<=6;k++)
{
System.out.print( k + ” “);
if ( k > 3)
{
break;
}
}
It will print 1 2 3
(f) Write the output of the following code :
int y = 6; do
{
System.out.print( y++ + ” .. ” )
y++;
}
while ( y <= 12);
Answer:
6 ..8 ..10 ..12 ..
(g) Write the output of the following code :
for ( k = 100; k > 55; k= k – 5)
{
if ( k%2 = = 0)
{
continue ;
}
System.out.print(k + ” “);
}
Answer:
95, 85, 75, 65.
Section – B
(Attempt Any four)
Question 4.
Input a number in K. Calculate the print the result of the following formulae :
W = (7*K + K2 ) / 2
Answer:
import java.util.*; public class Q5 { void main( ) Scanner sc = new Scanner (System.in); double K = 0.0, W = 0.0; System.out.print("Enter a number : "); K = sc.nextDouble( ); W = (7 * K + K*K )/ 2; System.out.print(" Value of K = " + K + " & Result W = " + W ); } }
Variable Description Table
Variable Name | Data type | Use |
K | double | Input variable |
W | double | Result |
Output :
Enter a number : 11.5
Value of K = 11.5 & Result W = 106.375
Question 5.
Input two numbers and find the max and min. Show the use of the ternary operator.
Answer:
import java.util.*; public class Q6 { void main( ) { Scanner sc = new Scanner (System.in); int nl = 0, n2 = 0, max - 0, min = 0; System.out.print("Enter 1st number :"); n1 = sc.nextlnt( ) ; System.out.print("Enter 2nd number n2 = sc.nextlnt( ); max (n1 > n2) ? n1 : n2; min = (n1 < n2) ? n1 : n2; System.out.println(" Max of " + nl + " and " + n2 + " = " + max ); System.out.print(" Min of " + nl + " and " + n2 + " = " + min ); } }
Variable Description Table
Variable Name | Data type | Use |
n1, n2 | int | Input variables |
max | int | Result of maximum |
min | int | Result of minimum |
Output :
Enter 1st number : 54
Enter 2nd number : 68
Max of 54 and 68 = 68
Min of 54 and 68 = 54
Question 6.
Input a number and print the corresponding day of the week. Assume that a. week begins with Sunday with day number being 1. Valid day numbers are from 1 to 7. Use switch..case operator.
Answer:
import java.util.*; public class Q7 void main ( ) throws IOException { Scanner sc = new Scanner (System.in); int wn = 0; System.out.print(”Enter day number:”); wn = sc.nextlnt( ) ; switch (wn) { case 1: System.out.print(”\n When wn = “+ wn + “ the weekday is SUNDAY.”); break; case 2: System.out.print(”\n When wn = “ + wn + “ the weekday is MONDAY.”); break; case 3: System.out.print(”\n When wn = “ + wn + “ the weekday is TUESDAY.”); break; case 4: System.out.print(”\n When wn =‘‚ + wn + “the weekday is WEDNESDAY.”); break; case 5: System.out.print(”\n When wn =“ + wn +“ the weekday is THURSDAY.”); break; case 6: System.out.print(”\n When wn =‘‚ + wn +“ the weekday is FRIDAY.”); break; case 7: System.out.print(”\n When wn = “ + wn + “ the weekday is SATURDAY.”); break; default: System.out.print(”\n wn = is an INVALID day number. “); } } }
Variable Description Table
Variable Name | Data type | Use |
wn | int | Input variable, day of week, its day number is to be printed |
Output :
Enter the week number : 7
When wn = 7 the weekday is SATURDAY.
Enter the week number : 0
wn = 0 is an INVALID day number.
Question 7.
Print the given series using a for loop.
10 2 30 4 50 6 … upto n terms
Answer:
import java.util.*; public class Q8 { void main( ) { Scanner sc = new Scanner (System.in); int n = 0; System.out.print("Enter number of terms : "); n = sc.nextlnt( ); for (int t = 1; t<=n; t++) { if (t %2 != 0) { System.out.print(" " + (t * 10) ); } else { System.out.print(" " + t); } } } } Variable Description Table
Variable Name | Data type | Use |
n | int | Input variable, number of terms |
t | int | loop counter indicating each term in the loop |
Output :
Enter number of terms : 10
10 2 30 4 50 6 70 8 90 10
Question 8.
Input a number of type integer. Calculate and print the product of its digits. Use while loop.
Answer:
import java.util.*; public class Q9 { void main( ) { Scanner sc = new Scanner (System.in); int n = 0, d = 0, p = 1; System.out.print("Enter a number : "); n = sc.nextlnt( ); int cn = n; while ( cn > 0) { d = cn%10; P = P * d; cn = cn/10; System.out.print(" Product of digits of " + n + " = " + p);
Variable Description Table
Variable Name | Data type | Use |
n | int | Input variable |
cn | int | copy of n, from which digits to be taken |
d | int | to store the digits of cn |
P | int | to store the product of digits |
Output :
Enter a number : 546
Product of digits of 546 = 120
Question 9.
Print the following pattern using nested for loop.
Answer:
import java.util.*; public class Q9 { void main( ) { for (int r = 5; r <-9; r++ ) { for (int c = r; c >=5; c - - ) { System.out.print(" " + c); } System.out.println( ); } } }
Variable Description Table
Variable Name | Data type | Use |
r | int | to store the row number |
c | int | to store the column number |