ANSWERS
Self Assessment Paper - 3
Section-A the arguments received. Since constructors have
same name as class and they return no values hence
the parameterised constructors also do not return
1.
any values.
(i) Option (d) is correct.
(xiv) Option (a) is correct.
Explanation: Polymorphism is an OOPS concept
Explanation: Call by reference is a way to invoke
that means one thing in many different forms.
a function or method. It uses the objects to call a
(ii) Option (a) is correct. method.
Explanation: Java does not support multiple (xv) Option (b) is correct.
inheritance.
Explanation: The Double.parseDouble() converts the
(iii) Option (b) is correct. string “71.25” to 71.25 + 0.75 gives 72.0.
Explanation: The ASCII code of ‘b’ is 98. Hence, r (xvi) Option (d) is correct.
will store 98.
Explanation: There are other classes than the Scanner
(iv) Option (c) is correct. class, whose functions may be used for taking input
Explanation: The logical operator not (!) takes only a in Java.
single operand and returns its reverse. (xvii) Option (a) is correct.
(v) Option (b) is correct. Explanation: n%10 gives the last digit and n/10
Explanation: The Scanner class is a Derived class reduces the number by a digit. The reduced number
used to input data of various primitive types using can then be again done a, %10 to get the 2nd last
methods like nextInt(), nextLine() etc. digit.
(vi) Option (d) is correct. (xviii) Option (b) is correct.
Explanation: x=Math.pow (15625, ½) + Math. Explanation: ar.length returns the number of
sqrt(144) + Math.pow(2,-2); elements in the array and ar[0] returns the 1st
= 125.0 + 12.0 + 0.25 element, So 5 + 23=28.
= 137.25 (xix) Option (b) is correct.
(vii) Option (c) is correct. Explanation: To check even number of digits, 1st the
loop for counting the number of digits starts, then
Explanation: Single-line comments are expressed
the count is maintained in a counter. The number is
using // in Java.
reduced by a digit in every iteration. Finally counter
(viii) Option (a) is correct. is checked for even.
Explanation: The isLetter() function checks whether (xx) Option (b) is correct.
the argument received is an alphabet or not and
Explanation: Strings cannot be changed in Java. The
returns a boolean true/false.
StringBuffer class has some functions like insert()
(ix) Option (a) is correct. etc. that make strings mutable.
Explanation: The startsWith() function checks
whether a string starts with a specific character or 2.
not. Java is case sensitive; hence, startsWith(‘l’) gives (i) for(int x=5;x<=5;x++);
false. System.out.println(x);
(x) Option (c) is correct. (ii) 39
Explanation: To check for factors the statement Explanation: z+ = a++ + --b + ++a + --b;
is if (n%i==0) c++;, The % operator returns the z = 10 + 10 + 4 + 12 + 3
remainder.
z = 39
(xi) Option (b) is correct.
(iii) Logical error
Explanation: Each element in the array occupies 4
bytes, so 10 elements will occupy 40 bytes. Correct code:
(xii) Option (c) is correct. int i;
Explanation: The return type is integer and the two for(int i=10;i<=50;i++)
arguments are also integers. if (i%2==0)
(xiii) Option (a) is correct. System.out.println(i);
Explanation: A parameterised constructor is a type (iv) Math.abs(x*x + x*y)
of constructor that initialises the data members by
2 | OSWAAL ICSE Sample Question Papers, COMPUTER APPLICATIONS, Class-10
(v) output 20 System.out.print(“Enter
The loop is not executed even once. employee age: “);
Explanation: Since the loop condition is false, the age = in.nextInt();
loop does not execute even once. The output comes System.out.print(“Enter basic salary: “);
as initial value of x = 10 × 2 = 20 basic = in.nextDouble();
(vi) (i) mittittippi }
Explanation: The replace() function replaces all public void calculate() {
occurrences of ‘S’ by ‘t’ and then convert the whole double hra,da,pf;
string to lowercase.
hra=(basic*18.5)/100;
(ii) –18 – 8 = –26
da=(basic*17.45)/100;
Explanation: “REDUCE”.compareTo (“REVOLT”)
pf=(basic*8.10)/100;
compares the two strings and returns the differences
between the ASCII codes of differing characters. net=basic+da+hra-pf;
“ANTARTICA”. lastIndexOf(‘A’) returns the index of }
the last occurrence of ‘A’ in the string public void print() {
(vii) The output will be: System.out.println(“Employee Number\
phoenixland tName\tAge\tBasic\tNet\n”);
ISLAND System.out.println(eno + “\t” + ename +
(viii) import java.util.Scanner; “\t” + age +”\t” + basic + “\t” + net);
int low=0,high=0, s=0; }
Scanner sc=new Scanner(System.in); public static void main(String args[]) {
System.out.println (“Enter the lower Employee obj = new Employee();
range:”); obj.accept();
low=sc.nextInt(); obj.calculate();
System.out.println (“Enter the upper obj.print();
range”:); }
high=sc.nextInt(); }
while (low<=high)
{
if (low%5==0)
Examiner's Comments
s+=low;
Most of the candidates answered this question
low++; correctly. Some candidates get confused with
} Syntax errors in the object creation and function
System.out.println(“Sum:”+s); call statement.
(ix) Global variables:a,b
Parameterised constructor
(x) (a) Since there are 10 elements the size of the array is Answering Tip
10.
(b) The position of 89 is 5, since indexes in java starts Students should learn all the concepts to write
from 0. syntax and calling function properly.
3. import java.util.Scanner;
public class Employee
{ 4. import java.util.*;
private int eno; public class linstring
private String ename; {
private int age; public void linsearch(String string[], String
search)
private double net;
{
private double basic;
int i;
public void accept() { int flag = 0,pos=0;
Scanner in = new Scanner(System.in); for(i = 0; i<10; i++)
System.out.print(“Enter employee number: {
“); if (string[i].startsWith(“SRI”))
eno = in.nextInt(); System.out.println(string[i]);
System.out.print(“Enter Name: “); if (search.equals(string[i]))
ename = {
in.nextLine(); flag = 1;
Answers | 3
pos=i; double min,max;
} Scanner scan=new Scanner(System.in);
} double arr[]=new double[20];
if (flag ==1) for(int i=0; i<20; i++){
{ System.out.print(“Enter the element
System.out.println(“Word found at position “+(i+1)+”: “);
“ +(pos+1)); arr[i]=scan.nextDouble();
}
min=arr[0];
else
max=arr[0];
{
for(int i=0; i<20; i++){
System.out.println(“Word not found.”);
if(min>arr[i]){
}
min=arr[i];
}
} if(max<arr[i]){ max=arr[i];
public static void main(String args[])
}
{
}
Scanner sc = new Scanner(System.in);
System.out.print(“Range of the array is:”+
String names[] = new String[10];
(max-min));
linstring obj=new linstring();
}
System.out.println(“Enter any 10 names.”);
int i; 7. import java.util.Scanner;
for (i = 0; i<10; i++) public class Menu {
{ public void series1(int n) {
names[i] = sc.nextLine(); for (int i = 1; i <= n; i++) {
} int term = i * i - 1;
System.out.println(“Enter name to be System.out.print(term + “ “);
searched.”); }
String search1 = sc.nextLine(); }
obj.linsearch(names, search1); public double series2(int n) {
} double sum = 0;
} for (int i = 1; i <= n; i++) {
5. import java.util.Scanner; sum = sum + (double) (2*i - 1)/(2* i);
class ProgReverse { }
public static void main (String[] args) return sum;
{ Scanner sc=new Scanner(System.in); }
String str=””, nstr=””; public void menu() {
char ch; Scanner scanner = new Scanner(System.in);
int vc=0; System.out.println(“1. Print 0, 3, 8,15,
System.out.println(“Enter a string:”); 24... n terms”);
str=sc.nextLine(); System.out.println(“2. Sum of series1/4 +
for (int i=0; i<str.length(); i++) 3/4 + 7/8 +,.. n terms”);
{ System.out.print(“Enter your choice:“);
ch= str.charAt(i); int choice = scanner.nextInt();
nstr= ch+nstr; System.out.print(“Enter n: “);
ch=Character.toUpperCase(ch); int n = scanner.nextInt();
if (ch==’A’ || ch==’E’ || ch==’I’ || switch (choice) {
ch==’O’ || ch==’U’) vc++; case 1:
} series1(n);
System.out.println(“Reversed word: “+ break;
nstr);
case 2:
System.out.println(“No. of vowels:” + vc);
double sum = series2(n);
}
System.out.println(sum);
}
break;
6. import java.util.Scanner; default:
class Range{ System.out.println(“Invalid choice”);
public static void main (String args[]){ }
4 | OSWAAL ICSE Sample Question Papers, COMPUTER APPLICATIONS, Class-10
} }
public static void main(String args[]) public boolean print(int n)
{ {
Menu men = new Menu(); //Check if n is a perfect cube
men.Menu(); int cubeRoot = (int)Math.round(Math.
} cbrt(n));
} if (cubeRoot * cubeRoot * cubeRoot == n) {
int s = 0;
8. import java.util.Scanner;
int t = n;
public class ProgOptionsNumber
while (t != 0) {
{
int d = t % 10;
public static void main(String args[])
s += d;
{ Scanner in = new Scanner(System.in);
t /= 10;
System.out.print(“1.Print Pattern “);
}
System.out.print(“2.Check Dudeney Number “);
if (s == cubeRoot) {
System.out.print(“3.Print Square / Cube “);
return true;
System.out.print(“Enter your choice:”);
}
int ch = in.nextInt();
else
if (ch==1)
return false;
{
}
print();
public void print()
}
{
else if(ch==2)
int i,j,k=1;
{
for(i=1;i<=4;i++)
System.out.print(“Enter number:”);
for(j=1;j<=i;j++)
int n=in.nextInt();
System.out.print(k++ + “ “);
print(n);
System.out.println();
}
}
else if(ch==3)
void print(int a,char ch)
{
{
System.out.print(“Enter number:”);
if (ch==’s’ || ch==’S’)
int n=in.nextInt();
System.out.println(a*a);
System.out.print(“Enter character(S-Square/
else if(ch==’c’ || ch==’C’)
C-Cube):”);
System.out.println(a*a*a);
char ch=in.nextLine().charAt(0);
}
print(n,ch);
}
qq