First Prep QP-X-CTA
First Prep QP-X-CTA
First Prep QP-X-CTA
3
(v) How many times will the following loop execute? What will be the output? [2]
for (int i=10;i<=100;i+=10)
{
if(i%3!=0)
continue;
System.out.println (i);
}
(vi) Write the output of the following String methods: [2]
(a) "CHROME".substring (2);
(b) "Classic".lastIndexOf ('C');
(vii) What are the two ways of invoking a method? [2]
(viii) Predict the output of the following code snippet. [2]
String a="14", b="12.5";
System.out.println (Double.parseDouble (a));
System.out.println (a.charAt (0) == b.charAt (0));
(ix) Name the following: [2]
(a) Name the variables that are common to all the objects of a class.
(b) At each stage, compares the sought key value with the key value of the middle
element of the array.
(x) int b[][]={{1,3},{5,7}}; [2]
(a) What will be the size of array b[][]?
(b) What is the value present at b[1][1]?
SECTION B
(Answer any four questions from this Section)
The answers in this section should consist of the programs in either BlueJ environment or
any program environment with java as the base.
Each program should be written using variable description/mnemonic codes so that the logic
of the program is clearly depicted.
Flowcharts and algorithms are not required.
Question 3 [15]
Define a class Grade_Revision having the following description:-
Instance Variables/Data Members:
String name - to store name of an employee
int bas - to store the basic salary
int expn - to store the years of service as experience
double inc - to store the increment
4
double nbas - to store the new basic salary (basic+increment)
Member Functions:
Grade_Revision ( ) - to intilalize name, bas, expn to their default values.
void input ( ) - to accept input for name, bas and expn.
[Using Scanner class only]
void compute ( ) - to calculate the increment with the following
specifications.
Experience Increment
Up to 3 years `1,000 + 10% of basic
More than 3 years and up to 5 years `3000 + 12% of basic
More than 5 years and up to 10 years `5,000 + 15% of basic
More than 10 years `8,000 + 20% of basic
Finally calculate the new basic salary as basic + Increment.
void display ( ) – print all the details of an employee.
Write a main ( ) method to create an object and call the functions.
Question 4
Define a class to search for a value input by the user from the list of values given below. If it
is found display the message "Search successful", otherwise display the message "Search
element not found” using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
Question 5 [15]
Define a class to accept a string and a character and convert both the string and the character
to lowercase and display the frequency of the character present in the string.
Example:
Input String: determination
Input Character: e
Output: The frequency of e is 2
Question 6 [15]
Define a class to input a number and check and print whether it is a Munchausen number or
not. A number is called Munchausen, if the sum of its digits raised to the power of itself is
equal to the input number.
Example:
Input number: 3435
Output: Munchausen number [33 + 44 + 33 + 55 = 3435]
5
Question 7 [15]
Define a class to accept integer values into 3x3 array and
(i) Print the reverse of an array in matrix format.
(ii) Find the average of ODD elements present in an array
Example:
Input: A[][]={{1,2,3},{4,5,6},{7,8,9}}
Output:
Reverse of an array
987
654
321
Average of ODD elements is 5.0 → (1+3+5+7+9)/5.0
Question 8 [15]
Define a class to overload the method print () as follows:
void print ( ) – To print the following pattern using nested for loop.
13579
1357
135
13
1
void print (int n) – print the square of all the even digits of the number ‘n’
Example:
If n is 172564
Output:
Squares of Even digits are:
16 →42
36 →62
4 →22
_________________