CTA Practice Paper 3
CTA Practice Paper 3
Consider the above picture and choose the correct statement from the following:
a. Vehicles is the object and the pictures are classes
b. Both vehicles and the pictures are classes
c. Vehicles is the class and the pictures are objects
d. Both vehicles and the pictures are objects.
(ii) Identify the type of error in the following code: double a; a=ob.nextInt();
a. Syntax Error b. Logical error
c. Runtime Error d. No error in the code
(iii) String a[]= {―MI‖, ―SAMSUNG‖, ―MICROMAX‖, ―ONE PLUS‖,
MOTOROLA};
Give the output of the following statement:
System.out.println(a[3].replace(‗O‘, ‗*‘));
a. *NE PLUS b. MICR*MAX
c. M*T*R*LA d. MI
(iv) An array elements are always stored in memory locations.
a. Sequential b. Random
c. Sequential and random d. Binary
(v) Give the output of the following : int x=2, y=4, z=1;
int result = (++z) + y + (++x) + (++z);
a. 11 b. 12
c. 10 d. 9
SNV/PRE/24-25/COMP/TT
Page 1 of 6
(vi) The array int a[] with 7 elements occupy:
a. 40 bytes b. 14 bytes
c. 7 bytes d. 28 bytes
(vii) What will be the value of a in the given code: double b=-15.6;
double a= Math.round(Math.abs(b));
System.out.println(―a=‖+a);
a. 14 b. 16 c. 16.0 d. 17.0
(viii) What will be the output of the following code: boolean p;
p = (―BLUEJ‖.length()> ―bluej‖.length()) ? true:false;
a. 1 b. 0 c. false d. true
(ix) For a given array int x[]= {11, 22, 33, 44, 55}; the value of x[1+2] is
a. 11 b. 22 c. 33 d. 44
(x) What will this code print?
int arr[] = new int [5];
System.out.println(arr);
a. 0 b. Value stored in arr[0]
c. 0000 d. Garbage value
(xi) What will be the final value stored in variable x? double
x=Math.max(Math.abs(-7.3),7.0);
a. 7.0 b. 7.3
c. 6.0 d. 8.0
(xii) Which of the following declaration and initialization in the below line
equivalent to?
String str= new String();
a. String str= ― ‖; b. String str= ― 0‖;
c. String str= null; d. String str= ― \0‖;
(xiii) Which of the following option is used to find the size of the given
array? char m[] = { ‗R‘ , ‗A‘, ‗J‘, ‗E‘, ‗N‘ , ‗D‘, ‗R‘, ‗A‘};
a. m.sizeOf(a); b. m.elementsof(m);
c. m.length; d. m.length();
Page 2 of 6
correct explanation of Assertion.
c. Assertion (A) is true Reason(R ) is false.
d. Assertion (A) is false Reason(R ) is true.
(xv) Assertion (A) while loop is an entry-controlled loop.
Reason ( R ) while loop execute the statements first and then checks the
condition.
a. Both Assertion (A) and Reason( R) are true and Reason (R) is a
correct explanation of Assertion(A)
b. Both Assertion (A) and Reason( R) are true and Reason (R) is not a
correct explanation of Assertion(A)
c. Assertion (A) is true and Reason( R) is false
d. Assertion (A) is false and Reason( R) is true
(xvi) Which of the following method returns a boolean value?
a. toLowerCase() b. toUpperCase()
c. parseInt() d. isUpperCase()
(xvii) Identify the correct array declaration
a. int [] d=new int[9]; b. int d[]=9;
c. int d[]=new int[]; d. int d[9];
(xviii) What will be the output of the following code?
System.out.println(―Lucknow‖.substring(0,4));
a. Lucknow b. Luckn
c. Luck d. Luckno
(xix) Consider the following code snippet : if(c>d) x=c; else x=d;
Choose the correct option if the code mentioned above is rewritten
using the ternary operator?
a. x=(c>d)?c:d; b. x=(c>d)?d:c;
c. x=(c>d)?c:c; d. x=(c>d)?d:d;
(xx)The technique in which the change in the formal parameter gets reflected in the
actual parameter is known as:
a. Call by reference b. Call by value
c. Call by argument d. Call by method
Question 2 [10X2=20]
(i) What is the output of the following code? char ch = ‗x‘;
char ch1=Character.toUpperCase(ch); int p= (int)ch1;
System.out.println(ch1+ ―\t‖+p);
(ii) What will be the output of the following code segment and how many times does
the loop execute?
Page 3 of 6
int a[]={2,4,12,6,10,14};
int m=0,n=0,p=0;
for(int k=0;k<2;k++)
{
m=a[2]++;
n=a[3]++;
p=a[4];
if(m==12)
break;
}System.out.print1n(m+n+p);
Page 4 of 6
(ix) State the datatype and value of b after the following code is executed:
char a= ‗8‘;
b=Character.isLetter(a);
(x) State the method.
i. Convert a string to a primitive float data type.
ii. Determines if the specified character is an upper case character.
Section B
(Answer any four questions from this Section.)
Data description table, Input/output, and comments is compulsory.
Question 3 [15]
Design a class name ShoppingMall with the following description:
Instance variables / Data members:
String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount
Member methods:
ShoppingMall () — default constructor to initialize data members
void accept() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased items, based on
following criteria
Cost Discount (in percentage)
Less than or equal to ₹10000 2%
More than ₹10000 and less than or equal to ₹20000 5%
More than ₹20000 and less than or equal to ₹35000 7%
More than ₹35000 10%
void print() — To display customer name, mobile number, amount to be paid after
discount.
Write a main method to create an object of the class and call the above member
methods.
Question 4 [15]
Write a program to enter to store 10 students and their 5 digit enrolment number in
two single dimensional arrays. Enter a name separately and search it in the given
list of names. If the name is present then display the name and corresponding
Page 5 of 6
enrolment number using linear search technique. If the name not found display
appropriate message.
Question 5 [15]
Write a program to calculate the norm of a number. Norm of a number is square
root of sum of squares of all digits of the number.
Example the norm of 68 is 10.
6X6+8X8=36+64=100. The square root of 100 is 10.
Question 6 [15]
Design a class to accept integers in a matrix (double dimensional) of 3x3
Display the sum of the left and right diagonal. If the left and right diagonal is same
then display the matrix as ―Cross Matrix‖ otherwise ―Non-Cross Matrix‖.
Question 7 [15]
Write a program in Java to accept a String in a mixed case (including digits and
special characters). Perform the following tasks as per the user‘s choice:
1. Count and display the number of vowels
2. Count and display the digits
3. Count and display the number of special characters excluding whitespaces
Sample Input: 15 August is celebrated as: ―Independence Day‖
Sample Output: Number of vowels : 15
Number of digits : 2
Number of special characters : 3
Question 8 [15]
Write a program to overload a function print() as per the details given below:
(a) void print (String st, Char ch) – to display all vowels in the string
if ch is ‗v‘ else display all the characters.
(b) void show(int p): To print the prime digits present in the given number
Example: p=4329
Output: 2, 3
(c) void print () – to print the following pattern.
1
3 1
5 3 1
7 5 3 1
Page 6 of 6