Library Classes Solutions ICSE Class 10 Computer Applications

ICSE Solutions for Class 10

Get ICSE Library Classes Solutions for class 10. It will help you to make good preparation before attending the ICSE Board exam.We have provided you with Library Classes Solutions class 10 to score good marks in your exam.

In ICSE CLass 10, Library Classes Solutions is compulsory to score good marks in computer applications. Students Who are planning to score higher marks in class 10 should practice ICSE Library Classes Solutions for class 10.

ICSE Library Classes Solutions for Class 10 Computer Applications

A. Tick (✓) the correct option.

1. Which of the following is a composite data type?
a. int
b. String
c. char
d. float

Answer

B

2. Which of the following is not a wrapper class?
a. Byte
b. Int
c. Long
d. Float

Answer

B

3. Which of the following is valid method of initialising?
a. Integer a=new (5);
b. Integer a=Integer(5);
c. Integer a=new Integer(5);
d. Integer a=new (“5”);

Answer

D

4. If s=“123”, which among the following will convert it to an integer?
a. int a=Integer(s);
b. int a=(int)s;
c. int a=parseInt(s);
d. int a=Integer.parseInt(a);

Answer

D

5. Which among the following is valid character initialisation?
a. Character c=new Character(‘c’);
b. Character c=new Character(“c”);
c. Both a and b
d. None of these

Answer

A

6. Which among the following methods return a true or a false?
a. toLowerCase()
b. toUpperCase()
c. parseInt()
d. isUpperCase()

Answer

D

7. What package is a part of the wrapper class which is imported by default into all Java programs?
a. java.util
b. java.lang
c. java.awt
d. None of these

Answer

B

8. Which class is inherited by the Character and Boolean wrapper classes?
a. Object
b. Number
c. Both a and b
d. None of these

Answer

A

9. What is, converting a primitive value into an object of the corresponding wrapper class called?
a. Autoboxing
b. Unboxing
c. Type Casting
d. All of these

Answer

A

10. Which among the following function is used to check whether a given character is a tab space or not?
a. isTab()
b. isTabSpace()
c. isSpace()
d. isWhitespace()

Answer

D

SECTION A

A. Answer the following questions.

1. What is composite data type?
Ans. In computer science, a composite data type or compound data type is any data type which can be constructed in a program using the programming language’s primitive data types and other composite types.

2. State the difference between primitive and composite data type.
Ans.

Library Classes

3. Explain with an example, how objects are passed as a reference.
Ans.
class PassByReference
{
      static void change(Number r)
      {
            r.a=r.a+5;
            r.b=r.b+5;
      }
            static void call()
      {
            Number n=new Number(5,6);
            System.out.println(n.a+“\t”+n.b);
            change(n);
            System.out.println(n.a+“\t”+n.b);
      }
}
will result in the following output when the call( ) function is executed:
5       6
10      1

4. What is a wrapper class? Name the wrapper classes used in java.
Ans. A Wrapper class is a class whose object wraps or contains a primitive data types. Wrapper classes used in Java- Byte, Short, Integer, Long, Character, Boolean, Float and Double.

5. Draw the wrapper class hierarchy.
Ans.

Library Classes

6. Show with an example, how wrapper class object can be created and initialised?
Ans. Example:
Byte b=new Byte(byte) 10):

7. Explain autoboxing and unboxing in java.
Ans. Converting a primitive value into an object of the corresponding wrapper class is called autoboxing. Converting an object of a wrapper type to its corresponding primitive value is called unboxing.

8. Explain the usage of <Wrapper Class>.parse…( ) method.
Ans. This function is used to convert a string to corresponding primitive data type. This function is present in all wrapper classes except Character and Boolean wrapper classes. The following example shows how this function can be used.
byte b=Byte.parseByte(“12”);
short s=Short.parseShort(“12”);
int i=Integer.parseInt(“123”);
long l=Long.parseLong(“98412”);
float f=Float.parseFloat(“12.3f”);
double d=Double.parseDouble(“12.46”);

9. What is the difference between isUpperCase() and toUpperCase() method?
Ans. The isUpperCase() method is used to check whether a given character is in uppercase or not.
The toUpperCase() method is used to convert a given character to uppercase.

10. What is the use of isWhitespace() method in Java?
Ans. A whitespace in Java is used as a space, tab, or a new line, and this method determines whether the given char(ch) is a whitespace or not.

11. Why is a class known as a composite data type?
Ans. A composite data type is one which is composed with various primitive data type. A class defined with various primitive data types such as int, double etc; so it is known as a composite data type; and it is used to create objects which hold similar types of values and behaviours (functions).

12. Name the package that contain the wrapper classes.
Ans. java.lang

B. Short answer type questions.

1. Answer as directed:
a. Assign a integer 123 to an int variable a.
b. Convert the variable a to a String and store it in the variable s.
Ans. a. int a=123;
b. String s=Integer.toString(a);

2. Answer as directed:
a. Assign an string “123” to a String variable a.
b. Convert the variable a to an integer and store it in the variable s.
Ans. a. String a=”123”;
b. int s=Integer.parseInt(a);

3. For the program given below mark the parts ___1___ and __2__ as autoboxing or unboxing.
class Example
{
      static void main()
      {
            Integer i;
            int sum=0;
            for(i=1;i<=10;i++) //___1___
            {
                  sum=sum+i; //__2__
            }
            System.out.println(sum);
      }
}
Ans. __1__:Autoboxing
__2__:Unboxing

4. Give the output of the following program when the main( ) method is executed:
class Overload
{
      static void wrapper(int a)
      {
            System.out.println(“int type=”+a);
      }
      static void wrapper(Integer a)
      {
            System.out.println(“Integer type=”+a);
      }
      static void main()
      {
            int b=13;
            Integer c=new Integer(b);
            wrapper(c);
            wrapper(b);
      }
}
Ans. Output:
Integer type=13
int type=13

5. Write one word answer for the following:
(i) A method that converts a string to a primitive integer data type
(ii) The default initial value of a boolean variable data type
Ans. (i) Integer.parseInt()
(ii) false

6. Write the output of the following:
(i) System.out.println (Character.isUpperCase(‘R’));
(ii) System.out.println(Character.toUpperCase(‘j’));
Ans. (i) true
(ii) J

7. State the method that:
(i) Converts a string to a primitive float data type
(ii) Determines if the specified character is an uppercase character
Ans. (i) Float.parseFloat()
(ii) Character.isUpperCase()

8. State the data type and the value of y after the following is executed:
char x =‘7’;
y = Character.isLetter(x);
Ans. y is of boolean type its value is false.

9. Write the return type of the following library functions:
(i) isLetterOrDigit(char)
(ii) parseInt()
Ans. (i) boolean
(ii) int

10. State the data type and value of res after the following is executed:
char ch=‘t’;
res=Character.toUpperCase(ch);
Ans. res is of char type is value is ‘T’.

11. Give the output of the following code:
String A=“26”, B=“100”;
String D=A+B+“200”;
int x=Integer.parseInt(A);
int y=Integer.parseInt(B);
int d=x+y;
System.out.println(“Result 1=”+D);
System.out.println(“Result 2=”+d);
Ans. Output:
Result 1= 26100200
Result 2=126

12. Write a difference between the functions isUpperCase() and toUpperCase().
Ans. Difference:

Library Classes

SECTION B

Write programs for the following:

1. Input a character and check whether it is an alphabet or not, if it is check whether it is in
uppercase or in lower case.
Example:
INPUT: A
Output: Uppercase
Input: 2
Output: Not an alphabet

Ans.
import java.util.*;
class Sol1
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            char c;
            System.out.println(“Enter a character:”);
            c=sc.next().charAt(0);
            if (Character.isLetter(c))
            {
                  if (Character.isUpperCase(c))
                        System.out.println(“Uppercase”);
                  else
                        System.out.println(“Lowercase”);
            }
            else
                  System.out.println(“Not an alphabet”);
      }
}

2. Create a function int sum(integer a) which accepts an Integer object as parameter and return the sum of its digits. In the main() input an integer and find the sum of its digits using the above method.

Ans. import java.util.*;
class Sol2
{
      static int sum(Integer a)
      {
            int d,s=0;
            while(a>0)
            {
                  d=a%10;
                  s+=d;
                  a/=10;
            }
            return s;
      }
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            Integer n,s;
            System.out.println(“Enter a Number:”);
            n=sc.nextInt();
            s=sum(n);
            System.out.println(“Sum:”+s);
      }
}

3. Create a function Boolean isPalindrome(Integer a) which checks whether the Integer object ‘a’ is a palindrome number or not. In the main input into an int type variable and check whether it is a palindrome number or not. Palindrome number is such a number which is same as its reverse,
example 121, 1331 etc.

Ans. import java.util.*;
class Sol3
{
      static Boolean isPalindrome(Integer a)
      {
            int i,c=0;
            for(i=1;i<=a;i++)
            {
                  if(a%i==0)
                        c++;
            }
            if(c==2)
                  return true;
            else
                  return false;
      }
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            Integer n;
            boolean f;
            System.out.println(“Enter a Number:”);
            n=sc.nextInt();
            f=isPalindrome(n);
            if(f)
                  System.out.println(“Palindrome”);
            else
                  System.out.println(“Not Palindrome”);
      }
}

4. Input 10 characters and find the frequency of uppercase and lowercase characters separately.
For example:
Input: A, b, c, d, E, F, G, H, I, j
Ouput: Uppercase Frequency: 6
Lowecase Frequency: 4

Ans.
import java.util.*;
class Sol4
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int i,u=0,l=0;
            char c;
            System.out.println(“Enter 10 characters:”);
            for(i=1;i<=10;i++)
            {
                  c=sc.next().charAt(0);
                  if(Character.isUpperCase(c))
                        u++;
                  else if(Character.isLowerCase(c))
                        l++;
            }
            System.out.println(“Uppercase Frequency:”+u);
            System.out.println(“Lowercase Frequency:”+l);
      }
}

5. Input 10 characters and concatenate only those characters which are either a letter or a digit.
For example:
Input: A, #, 1, d, E, F, %, H, 5, j
Ouput: A1dEFH5

Ans.
import java.util.*;
class Sol5
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int i;
            char c;
            String s=“ ”;
            System.out.println(“Enter 10 characters:”);
            for(i=1;i<=10;i++)
            {
                  c=sc.next().charAt(0);
                  if(Character.isLetterOrDigit(c))
                        s+=c;
            }
            System.out.println(“Result:”+s);
      }
}

6. Input an integer and form a new number by removing all odd digits from it.
For example,
Input: 123456
Output: 246

Ans.
import java.util.*;
class Sol6
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int n,d,i,nn;
            String s=””;
            System.out.println(“Enter a number:”);
            n=sc.nextInt();
            for(i=n;i>0;i/=10)
            {
                  d=i%10;
                  if(d%2==0)
                        s=d+s;
            }
            nn=Integer.parseInt(s);
            System.out.println(“Result:”+nn);
      }
}

7. Input an integer and remove all even digits and display it. Now check whether the new number is a perfect number or not.
Ans.
import java.util.*;
class Sol7
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int n,d,i,nn,sum=0;
            String s=””;
            System.out.println(“Enter a number:”);
            n=sc.nextInt();
            for(i=n;i>0;i/=10)
            {
                  d=i%10;
                  if(d%2!=0)
                        s=d+s;
            }
            nn=Integer.parseInt(s);
            for(i=1;i<nn;i++)
            {
                  if(nn%i==0)
                        sum+=i;
            }
            if(sum==nn)
                  System.out.println(“Perfect Number”);
            else
                  System.out.println(“Not a Perfect Number”);
      }
}

8. Input 10 characters and form a new string by concatenating all the characters by converting all
uppercase to lowercase and vice-versa.
For example:
Input: A, b, 1, d, E, F, G, H, @, #
Ouput: [email protected]#

Ans.
import java.util.*;
class Sol8
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int i;
            char c;
            String ns=””;
            System.out.println(“Enter 10 characters:”);
            for(i=1;i<=10;i++)
            {
                  c=sc.next().charAt(0);
                  if(Character.isUpperCase(c))
                  c=Character.toLowerCase(c);
                  else if(Character.isLowerCase(c))
                  c=Character.toUpperCase(c);
                  ns=ns+c;
            }
            System.out.println(“Result:”+ns);
      }
}

9. Design a class to overload a function sum() as follows:
(a) void sum(int n) – with one int argument that finds the sum of the digits in n.
(b) void sum(Integer n) – with one Integer argument that finds the sum of the digits in n.
Also create the main() method to call the above methods.

Ans.
class Overload
{
      void sum(int n)
      {
            int d,s=0;
            while(n>0)
            {
                  d=n%10;
                  s+=d;
                  n/=10;
            }
            System.out.println(“Sum=”+s);
      }
      void sum(Integer n)
      {
            Integer d,s=0;
            while(n>0)
            {
                  d=n%10;
                  s+=d;
                  n/=10;
            }
            System.out.println(“Sum=”+s);
      }
      void main()
      {
            int a=1234;
            Integer b=23498;
            sum(a);
            sum(b);
      }
}

10. Create a class called Number having the following members:
Instance Variables:
a and b of int type
Member Functions:
• Parameterised constructor to initailise a and b.
• void swap() that interchanges the value of a and b.
• void display() to display the data members.
In the main() method input 2 interchange their values using the methods of the above class.

Ans.
import java.util.*;
class Number
{
      int a,b;
      Number(int x,int y)
      {
            a=x;
            b=y;
      }
      void swap()
      {
            int t=a;
            a=b;
            b=t;
      }
      void display()
      {
            System.out.println(a+” “+b);
      }
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int x,y;
            System.out.println(“Enter 2 numbers:”);
            x=sc.nextInt();
            y=sc.nextInt();
            Number ob=new Number(x,y);
            ob.swap();
            ob.display();
      }
}

11. Create a class called StringNumber having the following members:
Instance Variables:
s of String type
n of int type
Member functions:
• StringNumber(String t) – to initialize s with t that contains a number (example “123”) and
n with 0.
• void assign() – assign the number stored in s to n after converting it to an integer.
• void largest() – find the largest digit in n and display it.
Also create the main to show the implementation.

Ans.
import java.util.*;
class StringNumber
{
      String s;
      int n;
      StringNumber(String t)
      {
            s=t;
            n=0;
      }
      void assign()
      {
            n=Integer.parseInt(s);
      }
      void largest()
      {
            int i,d,l=0;
            for(i=n;i>0;i/=10)
            {
                  d=i%10;
                  if(l==0)
                  l=d;
                  if(d>l)
                  l=d;
            }
            System.out.println(“Largest Digit:”+l);
      }
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            String s;
            System.out.println(“Enter a number:”);
            s=sc.nextLine();
            StringNumber ob=new StringNumber(s);
            ob.assign();
            ob.largest();
      }
}

12. Create a function Boolean isBouncy(Integer n) to check whether it is a Bouncy Number or not.
Increasing Number : Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 22344.
Decreasing Number : Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 774410.
Bouncy Number : We shall call a positive integer that is neither increasing nor decreasing a “bouncy” number; for example, 155349. Clearly there cannot be any bouncy numbers below 100.

Ans.
class Sol12
{
      Boolean isBouncy(Integer n)
      {
            int d,i,fa=0,fd=0,sd;
            for(i=n;i>9;i/=10)
            {
                  d=i%10;
                  sd=(i/10)%10;
                  if(sd>d)
                        fa=1;
                  if(sd<d)
                        fd=1;
            }
            if(fa==1 && fd==1)
                  return true;
            else
                  return false;
      }
}

13. Design a program to accept a positive whole number and find the binary equivalent of the number and count the number of 1’s in it and display whether it is a Evil number or not with an appropriate message. Output the result in format given below:
Example 1
INPUT : 15
BINARY EQUIVALENT : 1111
NO. OF 1’s : 4
OUTPUT : EVIL NUMBER
Example 2
INPUT : 26
BINARY EQUIVALENT : 11010
NO. OF 1’s : 3
OUTPUT : NOT AN EVIL NUMBER

Ans.
import java.util.*;
class Sol13
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int n,d,i,c=0;
            String s=“ ”;
            System.out.println(“Enter a number:”);
            n=sc.nextInt();
            for(i=n;i>0;i/=2)
            {
                  d=i%2;
                  if(d==1)
                        c++;
                  s=d+s;
            }
            System.out.println(“Binary Equivalent:”+s);
            System.out.println(“No. of 1’s:”+c);
            if(c%2==0)
                  System.out.println(“Evil Number”);
            else
                  System.out.println(“Not an Evil Number”);
      }
}

14. Write a Program in Java to input a number and check whether it is a Fascinating Number or not.
Fascinating Numbers : Some numbers of 3 digits or more exhibit a very interesting property.
The property is such that, when the number is multiplied by 2 and 3, and both these products are concatenated with the original number, all digits from 1 to 9 are present exactly once, regardless of the number of zeroes.
Let’s understand the concept of Fascinating Number through the following example:
Consider the number 192,
192 x 1 = 192
192 x 2 = 384
192 x 3 = 576
Concatenating the results : 192384576
It could be observed that ‘192384576’ consists of all digits from 1 to 9 exactly once. Hence, it could be concluded that 192 is a Fascinating Number.
Some examples of fascinating Numbers are : 192, 219, 273, 327, 1902, 1920, 2019, etc.

Ans.
import java.util.*;
class Sol14
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            long n,d,i,t,nn,f=0,j,c;
            String s=””;
            System.out.println(“Enter a number:”);
            n=sc.nextInt();
            for(i=1;i<=3;i++)
            {
                  t=n*i;
                  s=s+t;
            }
            nn=Long.parseLong(s);
            for(i=1;i<=9;i++)
            {
                  c=0;
                  for(j=nn;j>0;j/=10)
                  {
                        d=j%10;
                        if(d==i)
                              c++;
                  }
                  if(c!=1)
                        f=1;
            }
            if(f==0)
                  System.out.println(“Fascinating number”);
            else
                  System.out.println(“Not a Fascinating number”);
      }
}

15. Write a program to accept a number and check and display whether it is a Niven number of not.
(Niven number is that number which is divisible by its sum of digits).
Example:
Consider the number 126.
Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.

Ans.
import java.util.*;
class Sol15
{
      static void main()
      {
            Scanner sc=new Scanner(System.in);
            int n,d,i,s=0;
            System.out.println(“Enter a number:”);
            n=sc.nextInt();
            for(i=n;i>0;i/=10)
            {
                  d=i%10;
                  s=d+s;
            }
            if(n%s==0)
                  System.out.println(“Niven Number”);
            else
                  System.out.println(“Not a Niven Number”);
      }
}

ICSE Library Classes Solutions for class 10 Computer Application

We believe that every student can get good marks by solving Library Classes Solutions. So, let’s start to learn the Library Classes Solutionsclass 10 solution for your exam.

You can also learn revision note for class 10 computer application prepared by our expert teachers at icseboards.com