Notes For Class 11 Ev2 Syllabus Chapter

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

NOTES FOR CLASS 11 EV2 SYLLABUS CHAPTER- Numbers,methods and

constructors, Array and Strings,Recursion

Write a program to input a string (word). Convert it into lowercase letters. Count
and print the frequency of each alphabet present in the string. The output should
be given as:

Sample Input: Alphabets


Sample Output:
==========================
Alphabet Frequency
==========================
a 2
b 1
e 1
h 1
l 1
p 1
s 1
t 1
import java.io.*;
class AlphaFrequency

public static void main(String args[])throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


System.out.print(“Enter any string: “);
String s = br.readLine();

s=s.toLowerCase(); //converting the string into lowercase

int l=s.length(); //finding the length of the string

char ch;

System.out.println(“Output:”);
System.out.println(“==========================”);
System.out.println(“Alphabet\tFrequency”);
System.out.println(“==========================”);
/* Counting frequency of alphabets begins below */

int count=0;

for(char i=’a’; i<=’z’; i++)

count = 0;

for(int j=0; j<l; j++)

ch=s.charAt(j); //extracting characters of the string one by one

if(ch==i) //first checking the whole string for ‘a’, then ‘b’ and
so on

count++; //increasing count of those aplhabets which are present in the


string

if(count!=0) //printing only those alphabets whose count is not ‘0’

System.out.println(i+”\t\t”+count);
}

}
}

Enter any string: hai how are you


Output:

==========================

Alphabet Frequency

==========================

a 2

e 1

h 2

i 1

o 2

r 1

u 1

w 1

y 1

Input : n = 135Output : Yes 1^1 + 3^2 + 5^3 = 135Therefore, 135 is a Disarium


number

import java.util.*;
class DisariumNumber
{
int n,rem, sum,len;
DisariumNumber()
{
n =0;
rem = 0;
sum = 0;

}
void read()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number : ");
n = sc.nextInt();
}

void cal()
{
read();
int copy = n;
String s = Integer.toString(n); //converting the number into a String
len = s.length(); //finding the length of the number

while(copy>0)
{
rem = copy % 10; //extracting the last digit
sum = sum + (int)Math.pow(rem,len);
len--;
copy = copy / 10;
}
if(sum == n)
System.out.println(n+" is a Disarium Number.");
else
System.out.println(n+" is not a Disarium Number.");
}
public static void main(String[] args){
DisariumNumber ds= new DisariumNumber();
ds.cal();

}
}
Enter a number : 135
135 is a Disarium Number.
Enter a number : 234
234 is not a Disarium Number.
Enter a number : 89
89 is a Disarium Number.
Write program to find the whether the given number is evil number.
Write program to find whether the given number is Smith number
Program to check the prime number.
program to sort array using bubble sort
program to sort array using selection sort
program to search an element in array using linear search
program to search an element in array using binary search
Convert the following to their binary equivalents

(784)10

Answer
2 Quotient Remainder

2 784 0 (LSB)

2 392 0

2 196 0

2 98 0

2 49 1

2 24 0

2 12 0

2 6 0

2 3 1

2 1 1 (MSB)

Therefore, (784)10 = (1100010000)2

Question 2

(999)10

Answer

2 Quotient Remainder

2 999 1 (LSB)
2 Quotient Remainder

2 499 1

2 249 1

2 124 0

2 62 0

2 31 1

2 15 1

2 7 1

2 3 1

2 1 1 (MSB)

Therefore, (999)10 = (1111100111)2

Question 3

(1401)10

Answer

2 Quotient Remainder

2 1401 1 (LSB)

2 700 0
2 Quotient Remainder

2 350 0

2 175 1

2 87 1

2 43 1

2 21 1

2 10 0

2 5 1

2 2 0

2 1 1 (MSB)

Therefore, (1401)10 = (10101111001)2

Question 4

(1423)10

Answer

2 Quotient Remainder

2 1423 1 (LSB)

2 711 1
2 Quotient Remainder

2 355 1

2 177 1

2 88 0

2 44 0

2 22 0

2 11 1

2 5 1

2 2 0

2 1 1 (MSB)

Therefore, (1423)10 = (10110001111)2

Question 5

(478.75)10

Answer

Converting integral part

2 Quotient Remainder

2 478 0
2 Quotient Remainder

2 239 1

2 119 1

2 59 1

2 29 1

2 14 0

2 7 1

2 3 1

2 1 1

Converting fractional part

Multiply = Resultant Carry

0.75 x 2 = 0.5 1

0.5 x 2 = 0 1

Therefore, (478.75)10 = (111011110.11)2

Question 6

(165.35)10

Answer
Converting integral part

2 Quotient Remainder

2 165 1

2 82 0

2 41 1

2 20 0

2 10 0

2 5 1

2 2 0

2 1 1

Converting fractional part

Multiply = Resultant Carry

0.35 x 2 = 0.7 0

0.7 x 2 = 0.4 1

0.4 x 2 = 0.8 0

0.8 x 2 = 0.6 1
Therefore, (165.35)10 = (10100101.0101)2
(277.27)10

Answer

Converting integral part

2 Quotient Remainder

2 277 1

2 138 0

2 69 1

2 34 0

2 17 1

2 8 0

2 4 0

2 2 0

2 1 1

Converting fractional part

Multiply = Resultant Carry

0.27 x 2 = 0.54 0
Multiply = Resultant Carry

0.54 x 2 = 0.08 1

0.08 x 2 = 0.16 0

0.16 x 2 = 0.32 0

Therefore, (277.27)10 = (100010101.0100)2

Question 8

(322.2)10

Answer

Converting integral part

2 Quotient Remainder

2 322 0

2 161 1

2 80 0

2 40 0

2 20 0

2 10 0

2 5 1

2 2 0
2 Quotient Remainder

2 1 1

Converting fractional part

Multiply = Resultant Carry

0.2 x 2 = 0.4 0

0.4 x 2 = 0.8 0

0.8 x 2 = 0.6 1

0.6 x 2 = 0.2 1

Therefore, (322.2)10 = (101000010.0011)2

Perform the following

Question 1

(1010110)2 to ( )10

Answer

Binary
Power Value Result
No

0 (LSB) 20 1 0x1=0

1 21 2 1x2=2

1 22 4 1x4=4
Binary
Power Value Result
No

0 23 8 0x8=0

1 24 16 1x16=16

0 25 32 0x32=0

1 (MSB) 26 64 1x64=64

Equivalent decimal number = 2 + 4 + 16 + 64 = 86

Therefore, (1010110)2 = (86)10

Question 2

(1000011)2 to ( )10

Answer

Binary
Power Value Result
No

1 (LSB) 20 1 1x1=1

1 21 2 1x2=2

0 22 4 0x4=0

0 23 8 0x8=0

0 24 16 0x16=0

0 25 32 0x32=0

1 (MSB) 26 64 1x64=64
Equivalent decimal number = 1 + 2 + 64 = 67

Therefore, (1000011)2 = (67)10

Question 3

(1100111)2 to ( )10

Answer

Binary
Power Value Result
No

1 (LSB) 20 1 1x1=1

1 21 2 1x2=2

1 22 4 1x4=4

0 23 8 0x8=0

0 24 16 0x16=0

1 25 32 1x32=32

1 (MSB) 26 64 1x64=64

Equivalent decimal number = 1 + 2 + 4 + 32 + 64 = 103

Therefore, (1100111)2 = (103)10

Question 4

(10101011)2 to ( )10

Answer
Binary
Power Value Result
No

1 (LSB) 20 1 1x1=1

1 21 2 1x2=2

0 22 4 0x4=0

1 23 8 1x8=8

0 24 16 0x16=0

1 25 32 1x32=32

0 26 64 0x64=0

1 (MSB) 27 128 1x128=128

Equivalent decimal number = 1 + 2 + 8 + 32 + 128 = 171

Therefore, (10101011) 2 = (171)10

Question 5

(1010.001)2 to ( )10

Answer

Integral part

Binary
Power Value Result
No

0 20 1 0x1=0

1 21 2 1x2=2
Binary
Power Value Result
No

0 22 4 0x4=0

1 23 8 1x8=8

Fractional part

Binary
Power Value Result
No

0 2-1 0.5 0x0.5=0

0 2-2 0.25 0x0.25=0

1 2-3 0.125 1x0.125=0.125

Equivalent decimal number = 2 + 8 + 0.125 = 10.125

Therefore, (1010.001)2 = (10.125)10

Question 6

(10100.11)2 to ( )10

Answer

Integral part

Binary
Power Value Result
No

0 20 1 0x1=0

0 21 2 0x2=0
Binary
Power Value Result
No

1 22 4 1x4=4

0 23 8 0x8=0

1 24 16 1x16=16

Fractional part

Binary
Power Value Result
No

1 2-1 0.5 1x0.5=0.5

1 2-2 0.25 1x0.25=0.25

Equivalent decimal number = 4 + 16 + 0.5 + 0.25 = 20.75

Therefore, (10100.11)2 = (20.75)10

Question 7

(1010.111)2 to ( )10

Answer

Integral part

Binary
Power Value Result
No

0 20 1 0x1=0

1 21 2 1x2=2
Binary
Power Value Result
No

0 22 4 0x4=0

1 23 8 1x8=8

Fractional part

Binary
Power Value Result
No

1 2-1 0.5 1x0.5=0.5

1 2-2 0.25 1x0.25=0.25

1 2-3 0.125 1x0.125=0.125

Equivalent decimal number = 2 + 8 + 0.5 + 0.25 + 0.125 = 10.875

Therefore, (1010.111)2 = (10.875)10

Question 8

(1010.0111)2 to ( )10

Answer

Integral part

Binary
Power Value Result
No

0 20 1 0x1=0

1 21 2 1x2=2
Binary
Power Value Result
No

0 22 4 0x4=0

1 23 8 1x8=8

Fractional part

Binary
Power Value Result
No

0 2-1 0.5 0x0.5=0

1 2-2 0.25 1x0.25=0.25

1 2-3 0.125 1x0.125=0.125

1 2-4 0.0625 1x0.0625=0.0625

Equivalent decimal number = 2 + 8 + 0.25 + 0.125 + 0.0625 = 10.4375

Therefore, (1010.0111)2 = (10.4375)10

Question 1

(110101)2 - (011010)2

Answer

101001001−011010011011−100010110111000011101

Therefore, (110101)2 - (011010)2 = (11011)2

Question 2

(110110)2 - (01010)2

Answer
1100110−01010101100−111000011101110000

Therefore, (110110)2 - (01010)2 = (101100)2

Question 3

(101011)2 - (11101)2

Answer

100110011−11101001110−10001101011011101110

Therefore, (101011)2 - (11101)2 = (1110)2

Question 4

(11111)2 - (01101)2

Answer

11111−0110110010−101110110101110

Therefore, (11111)2 - (01101)2 = (10010)2

Question 5

(10000)2 - (01111)2

Answer

100101010−0111100001−1000011001100110011

Therefore, (10000)2 - (01111)2 = (1)2

Add octal numbers (1546)8 and (641)8

Answer

115146+6412407+1125164440617

Therefore, (1546)8 + (641)8 = (2407)8


Explanation

1. 6 + 1 = 7.
2. 4 + 4 = 8, as sum is equal to 8 so we will do 8 - 8 = 0. Hence, sum = 0,
carry over = 1.
3. 1 + 5 + 6 = 12, as sum is greater than 8 so we will do 12 - 8 = 4. Hence,
sum = 4, carry over = 1.
4. 1 + 1 = 2.

Question 2

Subtract octal number (2546)8 from (5142)8

Answer
5410432−25462374−542210534347264

Therefore, (5142)8 - (2546)8 = (2374)8

Explanation

1. 2 - 6, here 6 is greater than 2 so we borrow 1 from next significant


digit 4 and it becomes 3. Now 2 becomes 2 + 8 = 10 and 10 - 6 = 4.
2. 3 - 4, again 4 is greater than 3 so we borrow 1 from next significant
digit 1 and it becomes 0. Current digit 3 becomes 8 + 3 = 11. Lastly,
11 - 4 = 7.
3. 0 - 5, here 5 is greater than 0. Borrowing 1 from next significant digit
5 makes it 4. Current digit 0 becomes 0 + 8 = 8. Lastly, 8 - 5 = 3.
4. 4 - 2 = 2.

Question 3

Add hexa-decimal numbers (1F5C)16 and (AC2B)16

Answer

11�51�+��2���87+11ACFCB5128CB7

Therefore, (1F5C)16 + (AC2B)16 = (CB87)16


Explanation

1. C + B = 12 + 11 = 23. As 23 is greater than 16 so 23 - 16 = 7. Hence,


sum = 7 and carry over = 1.
2. 1 + 5 + 2 = 8.
3. F + C = 15 + 12 = 27. As 27 is greater than 16 so 27 - 16 = 11 or B.
Hence, sum = B and carry over = 1.
4. 1 + 1 + A = 1 + 1 + 10 = 12 or C.

Subtract hexa-decimal number (A68D)16 from (D53F)16

Answer

��543�−�68�2��2−DCA2546E38BFD2

Therefore, (D53F)16 - (A68D)16 = (2EB2)16

Explanation

1. F - D = 15 - 13 = 2.
2. 3 - 8, here 8 is greater than 3 so we borrow 1 from next significant digit
5 and it becomes 4. Now 3 becomes 3 + 16 = 19 and 19 - 8 = 11 or B.
3. 4 - 6, here again 6 is greater than 4 so we borrow 1 from next significant
digit D and it becomes C. Now 4 becomes 4 + 16 = 20 and 20 - 6 = 14
or E.
4. C - A = 12 - 10 = 2.

Question 5

Subtract hexa-decimal number (ABCD)16 from (EA9C)16

Answer

���998�−����3���−EDA3A9BE98CCCDF

Therefore, (EA9C)16 - (ABCD)16 = (3ECF)16

Explanation

1. C - D = 12 - 13, as 13 is greater than 12 so we borrow 1 from next


significant digit 9 and it becomes 8. Now 12 becomes 12 + 16 = 28 and
28 - 13 = 15 or F.
2. 8 - C = 8 - 12, as 12 is greater than 8 so we borrow 1 from next
significant digit A and it becomes 9. Now 8 becomes 8 + 16 = 24 and 24
- 12 = 12 or C.
3. 9 - B = 9 - 11, as 11 is greater than 9 so we borrow 1 from next
significant digit E and it becomes D. Now 9 becomes 9 + 16 = 25 and
25 - 11 = 14 or E.
4. D - A = 13 - 10 = 3.

Convert to Octal equivalents

Question 1

(4507)10

Answer

8 Quotient Remainder

8 4507 3 (LSB)

8 563 3

8 70 6

8 8 0

8 1 1 (MSB)

Therefore, (4507)10 = (10633)8

Question 2

(7757)10

Answer
8 Quotient Remainder

8 7757 5 (LSB)

8 969 1

8 121 1

8 15 7

8 1 1 (MSB)

Therefore, (7757)10 = (17115)8

Question 3

(7606)10

Answer

8 Quotient Remainder

8 7606 6 (LSB)

8 950 6

8 118 6

8 14 6

8 1 1 (MSB)

Therefore, (7606)10 = (16666)8


Give the output of this code
int a = 9; a++;
System.out.println (a);
a -= a – - – a;
System .out.println (a);

Ans: 10
8
Explanation
a = 9;
a++; // a = 10
SOP (a) // Prints 10
a -= a– – –a;
a = 10 – (10 – 8)
a = 10 -2 = 8
SOP (a) // Prints 8
c . What is the value stored in x and y after execution of these statements?
double x = Math.ceil(8.3) + Math.floor(-3.2)+Math.rint(4.5);
double y = Math.abs(Math.round(Math.max( -4.4, -9.6)));
Ans.
X = 9.0 Working: 9.0 + (-4.0) + 4.0 = 9.0
Y = 4.0 Working Math.abs(Math.round(-4.4)) = 4.0
d . Give the total number of bytes occupied by these arrays?
1.
1. int ar[25]
2. double A[12]
Ans. The number of bytes:
1.
1. ar[25] = 4*25 =100 bytes.
2. A[12] = 8*12 =96 bytes
e . What is the output of this code? Show the working
long num=729, sum 0;
for( long y= num; y> 0; y= y/10){
sum= sum + y % 10;
}
System.out.println("Sum of digits = "+ sum);

Ans. Sum of digits = 18

Initialization num = 729, sum = 0, y = 729


Iteration 1: sum = 0 + 729 % 10 = 9
Iteration 2: y = 729/10 = 72
sum = 9 + 72%10 = 11
Iteration 3 y = 72/10 = 7
sum = 11 + 7%10 = 18
y = 7/10 = 0 so the loop exits.
Print: Sum of digits = 18
What is the output of the following statements when executed?
char ch[ ]= {‘I’, ‘N’, T’, E’, ‘L’, P’, ‘E’, ‘N’, ‘T’, ‘I’, ‘U’, ‘M’};
String obj= new String(ch, 3, 4);
System.out.println(“The result is = “+ obj
Ans:
Output: ELPE
State the output of this program Segment?
String str1 = ”great”;
String str2= “Minds”;
System.out.println(str1.substring(0,2). Concat(str2.substring(1)));
System.out.println(( “WH”+(str1.substring(2).toUpperCase() )));

Ans.

The 1st output is= grinds ( because str1. Substring(0,2)gives “gr” & str2. Substring(1)
gives “inds”)
The 2nd output is= WHEAT ( because str1. Substring(2). toUpperCase() gives “EAT”,
so ”WH”+”EAT”= “WHEAT”)
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()

You might also like