0% found this document useful (0 votes)
25 views

II Prelim Revision 2024 computer

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)
25 views

II Prelim Revision 2024 computer

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/ 5

II PRELIM REVISION

1. Consider the array given below:

char ch[] = {‘A’, ‘E’, ‘I’, ‘O’, ‘U’};

Write the output of the following statement:

System.out.println(ch[0] * 2);

2. Learn the character class of all data types.

3. What will be the output of the following code?

System.out.println("computer".substring(0,4));

4. The method which returns String

a) length() b) charAt(int)

c) replace(char, char) d) indexOf(String)

5. What is the type of error, if any, when two methods have the same method signature?

a) Runtime error b) Logical error

c) Syntax error d) No error

6. Write Java statements for the following:

(a) To assign the cube root of -343 to a variable with the appropriate datatype.

(b) To assign the position of the last occurrence of @ in the String s with the

appropriate datatype.

7. Different ways to increase the value of a variable ‘x’ by 2.

8. A Character method that checks whether a character is an alphabet or a number.

9. b) A Math method that does not have an argument.

10. Suggest suitable method to convert long integer to string.

11. Predict the output

int i;

for( i=5; i>=1; i--)


{

if(i%2 == 1)

continue;

System.out.print(i+" ");

12. To convert an if program to switch……case.

13. Consider the following program segment and answer the questions given below:

int x[][] = {{3,5,6,9}, {5, 7, 8, 1}, {2, 4,6,4}};

(a) What is the position of 8?

(b) What is the result of x[2][3] + x[1][2]?

14. One question on Convert the for into do..while loop

15. One question on predict the output on substring , equalsIgnoreCase …

16. One question on to calculate how many bytes based on a given data type.

17. Which keyword makes a variable a class variable.

18. Difference between unary and binary operator.

19. Learn all the keywords, and the tokens to identify.

Programming Questions

1)Define a class to accept the Gmail ID and check for its validity.
A Gmail ID is valid only if it has:
→@
→ . (dot)
→ gmail
→ com
Example: [email protected] is a valid Gmail ID.
2) Sam designs a program to check the strength of a password. A strong password should
satisfy the following conditions:
→length of the password should be atleast 12 characters
→should atleast have 4 upper case letters, 4 lower case letters, 2 digits, 2 special
characters
Define a class accept the password and check whether the password is strong or not.

3) Write a program to input a sentence and convert it into uppercase and count and display
the total number of words starting with a letter 'A'.

Example:

Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE


EVER CHANGING.

Sample Output: Total number of words starting with letter 'A' = 4

4) Define a class with the following specifications:


Class name: Bank
Member variables:
double p – stores the principal amount
double n – stores the time period in years
double r – stores the rate of interest
double a – stores the amount
Member methods:
void accept() – input values for p and n using Scanner class methods only.
void calculate() – calculate the amount based on the following conditions:

Time in (Years) Rate %

Up to ½ 9

> 1/2 to 1 year 10

> 1 to 3 years 11

> 3 years 12
void display() – displays the details in the given format:

Principal Time Rate Amount


xxx xxx xxx xxx
Write the main() method to create an object and call the above methods.

5)Define a class to accept values into 4 × 4 array and find and display the sum of each row.
Example:
A[][] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {1, 3, 5, 7}, {2, 5, 3, 1}};
Output:
sum of row 1 = 10 (1 + 2 + 3 + 4)
sum of row 2 = 26 (5 + 6 + 7 + 8)
sum of row 3 = 16 (1 + 3 + 5 + 7)
sum of row 4 = 11 (2 + 5 + 3 + 1)

6)Define a class to accept a 3 digit number and check whether it is a duck number or not.

Note: A number is a duck number if it has zero in it.


Example 1:
Input: 2083
Output: Invalid
Example 2:
Input: 103
Output: Duck number

7)Define a class to print the Floyds triangle of given rows using nested loops only.
Example:
A Floyd triangle of 6 rows is
1
23
456
7 8 9 10
11 12 13 14 15
16 17 18 19 20 2
Define a class to print the sum of the following series: 1+(1+2)+(1+2+3)+..........(1+2+3……20

8) Define a class to overload the method display() as follows:


void display(): To print the following format using nested loop.

12121
12121
12121
void display(int n, int m): To print the quotient of the division of m and n if m is greater than n
otherwise print the sum of twice n and thrice m.
double display(double a, double b, double c): to print the value of z where z = p × q
p = (a + b) / c
q=a+b+c

9)Write a Java program to accept an employee ID as an integer from the user in ascending
order. Use the binary search technique on a sorted array of employee ID’s to determine if the
entered ID exists. If the record exists, display the message “Employee record found”, otherwise
display “Employee record not found”.
10) Write a program to accept numbers in a 4×4 matrix, then print all prime numbers present
in the matrix with array index value.
Sample input
16 15 1 2
6 4 10 14
9 8 12 5
3 7 11 13
Sample output:
Prime numbers in the matrix with their indices:
Prime Number: 2 at Index: [0][3]
Prime Number: 5 at Index: [2][3]
Prime Number: 3 at Index: [3][0]
Prime Number: 7 at Index: [3][1]
Prime Number: 11 at Index: [3][2]
Prime Number: 13 at Index: [3][3]

You might also like