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

Class 11 Ev2 Notes

Here are programs to solve the given problems: 1. To reverse a number: ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); int num = sc.nextInt(); int reverse = 0; while(num != 0) { int rem = num % 10; reverse = reverse * 10 + rem; num /= 10; } System.out.println("Reverse of given number is: " + reverse); } } ``` 2. To find vowels count in a string

Uploaded by

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

Class 11 Ev2 Notes

Here are programs to solve the given problems: 1. To reverse a number: ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a number: "); int num = sc.nextInt(); int reverse = 0; while(num != 0) { int rem = num % 10; reverse = reverse * 10 + rem; num /= 10; } System.out.println("Reverse of given number is: " + reverse); } } ``` 2. To find vowels count in a string

Uploaded by

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

Notes

Question 1

Which of the following is the correct usage?

1. int a[-40]
2. int a[40] ✓
3. float a[0 - 40]
4. None

Question 2

Which element is represented by a[10]?

1. 10th
2. 9th
3. 11th ✓
4. None

Question 3

Cell numbers of a dimensional array are also known as:

1. packets
2. blocks
3. subscripts ✓
4. compartments

Question 4

A dimensional array is also known as:

1. subscripted variable ✓
2. actual variable
3. compound variable
4. none

Question 5

An array element can be accessed through:


1. dots
2. element name
3. index number ✓
4. none

Question 6

Indicate the error message which displays, if the following statement is


executed :
int a[5] = {28,32,45,68,12};

1. Insufficient cells
2. Array index out of bounce
3. Elements exceeding cells
4. None ✓

Question 7

The following statement :


int code[ ]= {25,37,38,42};

1. assigns 37 to code[1] ✓
2. assigns 25 to code[1]
3. assigns 38 to code[3]
4. assigns 42 to code[0]

Question 8

The elements of array[50] are numbered:

1. from 1 to 50
2. from 0 to 49 ✓
3. from 1 to 51
4. none

Question 9

Which of the following function finds the size of array


char m[] = {'R', 'A', 'J', 'E', 'N', 'D', 'R', 'A' };?

1. m.size of (a)
2. m.elements of (m)
3. m.length ✓
4. None

Question 10

A Single Dimensional array contains N elements. What will be the last


subscript?

1. N-1 ✓
2. N
3. N+1
4. None

Give the output of the following

Question 1

int m[] = {2,4,6,8};


System.out.println(m[1] + " " + m[2]);

Output

46

Explanation

m[1] gives the second element of the array which is 4


m[2] gives the third element of the array which is 6

Question 2

int a[] ={2,4,6,8,10};


a[0]=23;
a[3]=a[1];
int c= a[0]+a[1];
System.out.println("Sum = "+c);

Output

Sum = 27
Explanation

a[0]=23 assigns 23 to the first element of the array. a[3]=a[1] assigns the value
of second element of the array which is 4 to the fourth element of the array.
After the execution of these two statements array looks like this:
{23, 4, 6, 4, 10}
a[0]+a[1] ⇒ 23 + 4 ⇒ 27

Question 3

int a[]=new int [5];


a[0]=4; a[1]=8; a[2]=7; a[3]=12; a[4]=3;
System.out.println(a[2+1]);

Output

12

Explanation

a[2+1] ⇒ a[3] ⇒ 12

Question 4

int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
System.out.println(s);
}

Output

10
10
toUpperCase()

It converts a string into upper case characters. If any character is already


in uppercase or is a special character then it will remain same.

Syntax:

String <variable-name> = <string-variable>.toUpperCase();


Question 2

trim()

It removes all leading and trailing space from the string.


Syntax:

String <variable-name> = <string-variable>.trim();

Question 3

toLowerCase()

It converts a string into lowercase characters. If any character is already


in lowercase or is a special character then it will remain same.

Syntax:

String <variable-name> = <string-variable>.toLowerCase();

Question 4

length()

It returns the length of the string i.e. the number of characters present in
the string.

Syntax:

int <variable-name> = <string-variable>.length();

Question 5

replace()

It replaces a character with another character or a substring with another


substring at all its occurrences in the given string.

Syntax:

String <variable-name> = <string-variable>.replace(<character or substring to


replace>, <new character or substring>);

Question 6

compareTo()
It compares two strings lexicographically.

Syntax:

int <variable-name> = <string-variable>.compareTo(<string-variable2>);

Question 7

reverse()

It is a method of StringBuffer class used to reverse the sequence of characters.

Syntax:

<StringBuffer-Variable>.reverse();

Question 8

indexOf()

It returns the index within the string of the first occurrence of the
specified character or -1 if the character is not present.

1. Write a program to reverse a number


2. Write a program to find the vowels count
3. Write a program to find even and odd number.
4. Write a program to find largest number among two.
5. Write a program to reverse and find whether it is palindrome string.
6. Write a program to find sum of two numbers.
7. Write a program to find the given number even or odd.
8. Write a program to find first capital letter of the given word.

You might also like