II Prelim Revision 2024 computer
II Prelim Revision 2024 computer
System.out.println(ch[0] * 2);
System.out.println("computer".substring(0,4));
a) length() b) charAt(int)
5. What is the type of error, if any, when two methods have the same method signature?
(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.
int i;
if(i%2 == 1)
continue;
System.out.print(i+" ");
13. Consider the following program segment and answer the questions given below:
16. One question on to calculate how many bytes based on a given data type.
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:
Up to ½ 9
> 1 to 3 years 11
> 3 years 12
void display() – displays the details in the given format:
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.
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
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]