You are on page 1of 8

PATHFINDER EDUCATIONAL CENTRE LLP

ICSE - X : 2023 – ’24 COMPUTER APPLICATION Mock Test – 2


Model Answer

SECTION A
1. (i) (c) Conditional Operator/ Ternary Operator
(ii) (d) double
(iii) (b) 13.0
(iv) (b) void
(v) (a) – 48.0
(vi) (b) Formal parameter
(vii) (c) return
(viii) (a) 522
(ix) (b) Float
(x) (b) double
(xi) (d) boolean, short, int, double
(xii) (c) System.out.print(arr[0]+arr[9]);
(xiii) (c) From within the current class to which it belongs, its subclasses, and also from within the same
package in which the current class is defined.
(xiv) (b) 18.43f
(xv) (b) Continue
(xvi) (b) – 84
(xvii) (b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion(A)
(xviii) (c) 26
(xix) (d) System.out.print(“MICHIGAN”.lastIndexOf(‘I’));
(xx) (a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A)
2. (i) – 35
(ii) double s=Math.sqrt(Math.pow(d,4) – Math.pow(r,3));
(iii) boolean agm=true;
boolean atd=false;
if(agm && !atd)
System.out.print(“Rajiv will be awarded a gold medal”);
else
System.out.print(“Rajiv will not be awarded a gold medal”);
(iv) class Hello
{
public static void main(String args[])
{
int n=12;
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

for(int i=2;n>1;)
{
if(n%i==0)
{
System.out.print(i+‘‘,”);
n=n/i;
}
else
i++;
}
}
}
(v) The do-while loop gets executed for 5 times.
The output of the given code is :2, 4, 7, 10, 13,
(vi) The output of the statement is :gaphollend
(vii) 167
(viii) Sum is :176
(ix) ANB3
(x) Default values for boolean data type is false and that for float data type is 0.0f.
SECTION B
3. import java.util.Scanner;

class VehicleTaxFine
{
private String vehNo;
private int roadTax,dur;
private double fine;

public VehicleTaxFine()
{
vehNo=””;
roadTax=dur=0;
fine=0.0;
}

public void accept()


{
Scanner sc=new Scanner(System.in);
System.out.print(“\nEnter Vehicle Number :”);

2
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

vehNo=sc.next();
System.out.print(“\nEnter the road tax amount :”);
roadTax=sc.nextInt();
System.out.print(“\nEnter the duration of late payment of tax in months :”);
dur=sc.nextInt();
}
public void calcFine()
{
if(dur<=6)
fine=0.05*roadTax;
else
if(dur<=9)
fine=4000+0.1*roadTax;
else
if(dur<=12)
fine=10000+0.15*roadTax;
else
fine=14000+0.25*roadTax;
}
public void display()
{
System.out.print(“\nVehicle Number :”+vehNo);
System.out.print(“\nRoad Tax Amount :”+roadTax);
System.out.print(“\nDuration of Late Payment of Tax :”+dur);
System.out.print(“\nRoad Tax Fine :”+fine);
}

public static void main(String args[])


{
VehicleTaxFine vt=new VehicleTaxFine();
vt.accept();
vt.calcFine();
vt.display();
}
} VDT – 2
4. import java.util.Scanner;

class SortWords
{

3
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

public static void main(String args[])


{Scanner sc=new Scanner(System.in);
System.out.print(“\nEnter the number of words :”);
int n=sc.nextInt();
String ss=sc.nextLine();
String w[]=new String[n];
System.out.print(“\nEnter the words :”);
for(int i=0;i<n;i++)
{
w[i]=sc.nextLine();
}

// sorted list of words


System.out.println(“\nUnsorted List of Words :”);
for(int i=0;i<n;i++)
{
System.out.print(w[i]+”, “);
}

for(int i=0;i<n-1;i++)
{
String sm=w[i];
int pos=i;
for(int j=i+1;j<n;j++)
{
if(sm.compareTo(w[j])>0)
{
sm=w[j];
pos=j;
}
}
if(pos!=i)
{
String s=w[i];
w[i]=w[pos];
w[pos]=s;
}
}

4
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

// sorted list of words


System.out.println(“\nSorted List of Words :”);
for(int i=-0;i<n;i++)
{
System.out.print(w[i]+”, “);
}
}
} VDT–2
5. import java.util.Scanner;
class Disarium
{

public static int countDigits(int num)


{
int c=0;
while(num>0)
{
c++;
num=num/10;
}
return c;
}

public static int getSum(int num)


{
int s=0,d=0,c=countDigits(num);
while(num>0)
{
d=num%10;
num=num/10;
s=s+(int)Math.pow(d,c); c – –;
}
return s;
}

public boolean isDisa(int num)


{
int s=getSum(num);
if(s==num)

5
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

return true;
else
return false;
}

public void display(int x,int y)


{
System.out.print(“\nList of Disarium Numbers :”);
for(int i=x;i<=y;i++)
{
if(isDisa(i)==true)
System.out.print(i+”, “);
}
}

public static void main(String args[])


{
Disarium d=new Disarium();
Scanner sc=new Scanner(System.in);
System.out.print(“\nEnter the lower and upper limits of the range :”);
int a=sc.nextInt(),b=sc.nextInt();
d.display(a,b);
}
} VDT–2
6. import java.util.Scanner;

class WordCipher
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(“\nEnter any word :”);
String w=sc.next(),nw=””;
int len=w.length();
for(int i=0;i<len;i++)
{
char ch=w.charAt(i);
if(ch==’z’)
ch=’a’;

6
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

else
if(ch==’Z’)
ch=’A’;
else
ch+=1;
nw=nw+ch;
}
System.out.print(“\nNew Word :”+nw);
}
} VDT–2
7. import java.util.Scanner;

class LinearSearch
{
public static void main(String args[])
{
int a[]={19,74,-34,72,67,48,92,-68,83,-18};
Scanner sc=new Scanner(System.in);
System.out.print(“\nEnter the value to search :”);
int val=sc.nextInt();
boolean flag=false;
for(int i=0;i<a.length;i++)
{
if(a[i]==val)
{
System.out.print(“\nValue is present at position :”+(i+1));
flag=true;
break;
}
}
if(flag==false)
{
System.out.print(“\nNo such is present in the array “);
}
}
} VDT–2

7
ICSE – X : 2023–’24 Computer Application : Mock Test–2 MODEL ANSWER

8. import java.util.Scanner;

class MatrixSum
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print(“\nEnter the contents of the matrix :”);
int arr[][]=new int[4][4];
int sum1=0,sum2=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
arr[i][j]=sc.nextInt();
}
}
for(int i=0;i<4;i++)
{
for(int j=i+1;j<4;j++)
{
sum1=sum1+arr[i][j];
}
}
System.out.print(“\nSum of all the elements of the matrix above the left diagonal :”+sum1);

for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(i==0 || i==3 || j==0 || j==3)
sum2=sum2+arr[i][j];
}
}
System.out.print(“\nSum of all the peripheral elements of the matrix :”+sum2);
}
} VDT–2

You might also like