0% found this document useful (0 votes)
14 views6 pages

2022 11 28 X ICSE Computer Solution - PMD

Uploaded by

Aradhya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

2022 11 28 X ICSE Computer Solution - PMD

Uploaded by

Aradhya Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Prerna Tower, Road No - 2, Contractors Area, Bistupur, Jamshedpur-01, Phone : 0657-2221892, www.prernaclasses.

com

X ICSE COMPUTER SOLUTION 28th NOVEMBER 2022


1. (a) i) A constructor has the same name as that of a class.
ii) A constructor does not have any return type.
iii) A constructor is automatically called during object creation.
iv) A constructor gets automatically overloaded.

(b) (i) 5over0 (ii) 71

(c) An instance method can only be invoked bound to an object of the class.
For example : player2.displayperformance ( );
The object player2 on which the instance method displayperformance( ) operates is
called implicit argument. The object variable bound to which an instance method is
invoked, is its implicit argument.

(d) Call by value: In call by value mechanism, a copy of Actual parameters are passed
to the Formal parameters. Hence any changes made in the Formal parameter’s do
not reflecton the Actual parameters. Thus, Actual parameters remain unchanged.
Here, variables are used as Actual and Formal arguments.
Call by reference: In this mechanism, the Actual and Formal paremeters both
represent the same memory location, since here objects are used as Actual and
Formal arguments (in Java). Henceforth changes made in Formal parameters get
reflected in the Actual parameters too.

(e) a=2 or positive data type : int


b= false data type : boolean

(f) A destructor is a method which is executed when the object is removed from
computer’s memory.

Sample(~)// a destructor with same name as that of its class followed by a tilde~

(g) The default constructor provided by the compiler initializes all instances variables to
their default values. It initialises integers to 0, floating point numbers to 0.0, boolean
values to false and objects to null.

(h) int x = 10, c = 20;


do
{
c = c – 2;
x ++;
} while (c > 10);

X ICSE Computer 28 November 2022 www. prernaclasses.com - 7 -


(i) private members are accessible only in the class in which they have been defined.
protected members are accessible in the class in which they have been defined as
well in the sub classes of that class.

(j) double z = ( 5 * Math.pow ( x, 3 ) + 2 * y ) / ( x + y ).

2. (a) (c) (b) (a) (c) (d) (d) (d) (e) (d)

(f) (c) (g) (d) (h) (c) (i) (b) (j) (a)

(k) (b) (l) (a) (m) (d) (n) (a) (o) (a)

(p) (b) (q) (b) (r) (a) (s) (a) (t) (c)

3. import java.util.*;
class Anagrams
{
int c = 0;
void input()throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a word : ");
String s = sc.next();
System.out.println("The Anagrams are : ");
display("",s);
System.out.println("Total Number of Anagrams = "+c);
}
void display(String s1, String s2)
{
if(s2.length()<=1)
{
c++;
System.out.println(s1+s2);
}

else
{
for(int i=0; i<s2.length(); i++)
{
String x = s2.substring(i, i+1);
String y = s2.substring(0, i);
String z = s2.substring(i+1);
display(s1+x, y+z);
} } }
public static void main(String args[])throws Exception
{ Anagrams ob=new Anagrams();
ob.input(); } }

X ICSE Computer 28 November 2022 www. prernaclasses.com - 8 -


4. import java.util.*;
class EvilNumber
{
String toBinary(int n) // Function to convert a number to Binary
{
int r;
String s=""; //variable for storing the result
char dig[]={'0','1'}; //array storing the digits (as characters) in a binary number system
while(n>0)
{
r=n%2; //finding remainder by dividing the number by 2
s=dig[r]+s; //adding the remainder to the result and reversing at the same time
n=n/2;
}
return s;
}
int countOne(String s) // Function to count no of 1's in binary number
{
int c = 0, l = s.length();
char ch;
for(int i=0; i<l; i++)
{
ch=s.charAt(i);
if(ch=='1')
{
c++;
}
}
return c;
}
public static void main(String args[])
{
EvilNumber ob = new EvilNumber();
Scanner sc = new Scanner(System.in);
System.out.print("Enter a positive number : ");
int n = sc.nextInt();
String bin = ob.toBinary(n);
System.out.println("Binary Equivalent = "+bin);
int x = ob.countOne(bin);
System.out.println("Number of Ones = "+x);
if(x%2==0)
System.out.println(n+" is an Evil Number.");
else
System.out.println(n+" is Not an Evil Number.");
}
}

X ICSE Computer 28 November 2022 www. prernaclasses.com - 9 -


5. import java.util.Scanner;
public class Cities
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
String[] cities = new String[10];
int[] std = new int[10];
for (int i = 0; i < 10; i++)
{
System.out.print("Enter city: "); cities[i] = scanner.next();
System.out.print("Enter std code: "); std[i] = scanner.nextInt();
}
System.out.print("Enter city name to search: ");
String target = scanner.next();
boolean searchSuccessful = false;
for (int i = 0; i < 10; i++)
{
if (cities[i].equals(target))
{
System.out.println("Search successful");
System.out.println("City : " + cities[i]);
System.out.println("STD code : " + std[i]);
searchSuccessful = true;
break;
}
}
if (!searchSuccessful) {System.out.println("Search Unsuccessful, No such city in the list");

} } }

6. import java.util.*;
class sortParagraph
{
// Function to count no. of words in every sentence
int countWords(String s)
{
StringTokenizer str = new StringTokenizer(s," .,?!");
int c = str.countTokens();
return c;
}
// Function to sort the sentences in ascending order of their no. of words
void sort(String w[], int p[])
{

X ICSE Computer 28 November 2022 www. prernaclasses.com -10-


int n = w.length, t1 = 0;
String t2 = "";
for(int i=0; i<n-1; i++)
{
for(int j=i+1; j<n; j++)
{
if(p[i]>p[j]) // for descending use p[i]<p[j]
{ t1 = p[i]; p[i] = p[j]; p[j] = t1; t2 = w[i]; w[i] = w[j]; w[j] = t2;
}
}
}
printResult(w,p); // Calling function for printing the result
}
void printResult(String w[], int p[]) // Function to print the final result

{ int n = w.length;
for(int i=0; i<n; i++)
{ System.out.println(w[i]+"\t=\t"+p[i]); } }

public static void main(String args[])


{
sortParagraph ob = new sortParagraph();
Scanner sc = new Scanner(System.in);
System.out.print("Enter a paragraph : "); //Inputting a paragraph
String pg = sc.nextLine();
StringTokenizer str = new StringTokenizer(pg,".?!");
int count = str.countTokens(); //Counting no. of sentences in the paragraph
if(count > 10)
System.out.println("A maximum of 10 sentences are allowed in the paragraph");
else
{
String sent[] = new String[count]; //Array to store the sentences separately
int p[] = new int[count]; //Array to store no. of words of each sentence
for(int i=0; i<count; i++)
{
sent[i] = str.nextToken().trim(); // Saving sentences one by one in an array
p[i] = ob.countWords(sent[i]); // Saving no. of words of every sentence
}
ob.sort(sent,p);
} } }

X ICSE Computer 28 November 2022 www. prernaclasses.com -11-


7. (a) import java.io.*;
public class Pat{
public static void main(String args[]) throws IOException
{
int k=65;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print((char)k+”*”);
k++;
}
System.out.println(“”);
}
}//Main
}// class

(b) import java.io.*;


public class Pat
{
public static void main(String args[]) throws IOException
{
int k=5,sp=3;
for(int i=7;i>=3;i—)
{
for(int j=1;j<=k;j++)
{
System.out.print(i); }
for(int s=1;s<=sp;s++)
{
System.out.print(“ “);
}
System.out.print(k);
System.out.println(“”);
k--;
sp++;
}
}//Main
}//Class

X ICSE Computer 28 November 2022 www. prernaclasses.com -12-

You might also like