1
TEST - 6
Section - A (40 Marks)
MaxMarks-100
Time- 2 hrs
Question 1.
1. How java compile its programs?
2. Define and then differentiate an interpreter from a compiler.
3. Differentiate between default constructor and parameter constructor
4. Give any two features of java.
5. Find the error in the given program segment.
Also write the correct statement.
CLASS DVD{
Public int check error (void)
int X , Y 10;
X=Y++
System. Out. Print ln (“result= X ,Y )
}}
[10]
(2)
(2)
(2)
(2)
(2)
Question 2.
How does java handle exceptions?
Mention any two return types of the method with example.
(5)
(5)
[10]
Question 3.
a. With an example, explain the working of selection sort in array.
b. What is constructor. Explain with an example program
(5)
(5)
Question 4.
a. Give an example to illustrate ‘BufferedReader’.
b. Explain the purpose Access modifiers in class ?
(5)
(5)
[10]
[10]
Section-B (60 marks)
Question 5. Write a program to print rainfall statistics as follows ….
This program reads a series of rainfall measurements (number of millimeters
of rain, one per day). It will then print the following statistics.(Use different functions )
Maximum. The largest amount of rain that fell in any one day.
Average rainfall per day. Compute this as a floating point number.
Input:
For eg. 1 0 12 7 0 0 11
Output:
Average rainfall = 4.428571428571429
Maximum rainfall = 12
[
15]
Question- 6
[15]
a. Write a java class bank account that is described below:
Members
Members name
Description
Member variables
AC num, AC name AC balance
Store account number, holder’s name
and balance.
Default constructor : Initialise AC num, AC name and AC balance.
Parameterised constructor:Initialise AC num, AV name, and AC balance with values accepted from
object.
(8)
b. Write a complete java program that defines the following methods:
Assign
: that assigns value to two numbers.
: that doubles the numbers assigned.
Display
: that displays the result.
Main : that calls all above methods.
Double
(7)
1
2
TEST - 6
Question- 7
a. Design a class data with 3 data members: day, month and year
Member methods:
(i) Accept date
(ii) Display the date
[15]
(7)
Write a java method that extracts first five characters of a string and last five characters of another string.
Compare them and prints ‘EQUAL’ if, they match else it-print ‘NOT EQUAL’.
(8)
Question- 8
a. If two matrices A and B are given as follows;
[15]
2 1
3 2
A
,B
5 6
1 4
Write a program to compute the sum of the two matrices and display the result in matrix C
(6)
Define a class student that implements the student constructor. Define another method in this class
compute average to check calculate the average of marks in three subject. Display values to display
the average marks of student.
(9)
Question- 9
a. Write a program to swap two numbers without using any temporary variable.
b. Code a program to enter 3 X 3 matrix. And store the array in another array by converting
rows to columns and columns to rows.
Question- 10
a) Code a program to enter 10 numbers in single dimensional array.
i)
Write a function to remove the duplicate values in an array.
ii)
Also print the array after deletion of duplicate entries
[15]
(8)
(7)
[15]
(8)
b) Write a java class star which initializes the two integer numbers 10 and 25 to variables and point the
result after. (Using different functions)
(i) Addition
(ii) subtraction (iii) multiplication
(iv) Division
(7)
2
3
TEST - 6
Subject – Computer Application
( Class : X )
( Two Hours)
SECTION A ( 40 Marks)
Q1. a)
b)
c)
d)
e)
Q2. a)
b)
c)
d)
e)
What is casting,when do we need it ?
[10]
State the rules of operator precedence.
Name the character set supported by java.
What are instance variable and instance methods?
What is difference between unary,Binary and Ternary operator? Give an example also.
What is a role of return statement in function.?
Define a function. What is function prototype?
Name the package you need to import for performing input and output.
What is syntax error and logical error?
Determine the total bytes required to store B[17] , a char array.
Q3. a) Find the output :- int a=10,b=15,c=25
i) (a==(b+c)&&b==(a-c)
ii) (a==)b+c)|| b==(a+c)
[10]
[10]
b) Write the corresponding expressions for the following mathematical operations: (i) | a | + b > = | b | +a
(ii) z = x3 + y3 – xy
c) What will be the output for the following program segment?
int a = 0, b = 30 , c = 40;
a = -- b + c ++ + b;
System.out.println(“ a=” + a);
d) Find the error of the following program segment,
Int m=1;n=0;
for (;m+n<19;++n)
System.out.Println (“Hello \n”);
m=m+10;
e) What will be the output of the following program
{ int a;
for(a=0;a<10;a++)
if (a==5)
break;
System.out.println(“ “+a); }.
Q4. a) Differentiate between Variable and Constant.
[10]
b) What is Composite Data type?
c) Find the output if a=--b+c+ ++b, where b=30 and c=40.
d) What are the preconditions for Binary search.
e) What is the role of void keyword in declaring function.
3
4
TEST - 6
SECTION B ( 60 Marks )
Q5. Write a program to Input any sentences and find the longest word. For eg. India is my country . Ans is
Longest word is Country
[15]
Q6. Write a program that outputs the results of the following evaluations based on the Choice entered by the
user.
[15]
i)
Print the Factors of the number.
ii)
Print the factorial of the number.
iii)
Check number is prime or not.
iv)
Check number is perfect or not.
Q7. Define a class with a member function to accept monthly salary from the user.Find and display Income
Tax with the help of following rules :[15]
Monthly Salary
Income tax
Rs. 9000 or More
40% of Monthly salary
Rs. 7500 to Rs. 8999
30% of Monthly salary
Rs. 7499 or less
20% of Montjly salary
Q8. Computer keeps information of 10 persons with their phone no., Name and addresses. Write a program
using Binary search technique in which user enters any phone number and computer prints the phone
no. , name and address of the person if found. In case information is not traced out print the message
"Information does not exist".
[15]
Q9. Write a program to print the Pascal triangle following series: 1
A
1 2 1
A
B
1 2 3 3 1
A B C
1 2 3 4 3 2 1
A B C D
[15]
Q10. Write a program to create a 4 * 4 matrix and input the numbers from the user. Now find the following:
i)
Sum of all the elements above diagonal in the matrix
ii)
Sum of the each row and each Column
iii)
The maximum and Minimum number present in the matrix with position.
[15]
Time- 2Hrs.
MM-100
SECTION A (40 Marks)
Attempt all questions from this Section.
Q1-
(a) Name the types of constructor in Java.
(b) Explain a block in a Java program.
(c) Write the difference between pure and impure functions.
(d) Explain the formal and actual parameters in a method.
(e) What is the significance of function overloading in Java?
Q2.
Write short notes on following
1. Constructors
2. Difference between “call by value” and “call by reference method”
3. “this” keyword
4. Function signature
5. Polymorphism
Q3. Write the output of following program segments(a)
[2*5]
[2*5]
4
TEST - 6
5
int i, j, arr[]= new int[7];
arr[0]=1;
for(i=0;i<6;i++)
{
for(j=0;j<=i;j++)
System.out.print(arr[j]+"\t");
for(j=i+1;j>0;j--)
arr[j]=arr[j]+arr[j-1];
System.out.println();
}
b) int a,b,I,j;
for(i=1; i <=3; i = i +1)
{
for(j=1;j<= i;j++)
{
System.out.println(“ “+j+””+ i);
}
System.out.println();
}
5
Test – 4
Q4. Write a program to search an element using binary search method.
Q5. Following program segment is to print the sum of the prime digits of an entered number.
e.g. input-1872
output- Sum of prime digits is 10 ( as 1,7 and 2 are prime digits in no. 1872)
6
[4]
[5]
int digit,sum=0,n=42981;
while(n>0)
{
?1?=n%10;
if(digit==1 || digit==2 || ?2? || ?3? || digit==7 )
sum=?4?;
n=?5?;
}
System.out.println(“sum of prime digits is “+sum)
Write the statements to fill in the blanks marked with question marks.
Q6. (1) Consider the following array declarations:
[2*3]
(a) int X[5][50]
(b) char Y[18] ,(i) Find the number of elements in each array.
(ii) Find the total number of bytes required to store each array.
(2) What is the value of x after evaluating x+=x+++--x+4; if x=3 before the evaluation?
(3) Name the primitive data types to represent real numbers.
Section –B(60 marks)
Q7 .(a) Write a program to input the number of a week and print the corresponding day. Assume 1
for Monday, 7 for Sunday, etc. also give the proper message for the wrong number input.
(b). Write a program to enter the name and convert its each lower case letters to uppercase
and vice versa.
Example :
Input - Subhash Chandra Bose
Output- sUBHASH cHANDRA bOSE
Q8. Write a program to input a sentence. Create a function convert(int n), where n is an integer value
in positive or negative. This function is used to encode or decode the given string by shifting each character of a
string the number of times as specified by user.
Ex.- Input- Good Boy
Shift value –3
Output – Jrrg Erb
You can see that this function does not affect the spaces. Also if it reaches end of the alphabet list it starts the
list again.(see the state of ‘y’ in “Boy” above, it changes to ‘b’). in the similar manner if the entered shift value of
n is in negative then all the characters in a string will shift backwards.
Q9. The distance between two cities is measured in Kilometers(km) and Meters(m). Thus to add distance of two cities
from the current city we need to add its km and m of one city with the km and m of other city. You must remember
that 1000 meters makes one(1) Kilometer. Write a class with the following data members to add the distance of two
cities from the current city.:
Class name
:
distance
Data members
Integer
:
km ,m
Methods Distance Run(distance,distance) : to input two distances and to add them into the third
Display
:
to display the total distance.
Display the constructor required to initialize the objects.
Q10. Write a program to create a double dimensional array[4*4] to store 16 elements and to perform the following
operations as per user choice1. To print the position of largest and least element
2. To print the sum of its diagonal elements
3. To print the sum of all the elements.
Q11. Design a class named “Database”. It has name, address, city, pin code and basic salary as data members. it also
has member functions to input data, print data and calculate Dearness allowance which is 150% of basic salary, House
rent which is 40% of basic salary and gross salary which is sum of basic, D.A. and H.R.A. A parameterized
constructor is used to pass initial values to arguments by implicit call method.
Define the class “ Database”. Also create an object of the class.
Test – 4
7
Q12. Write a program to initialize an array of 5 names and initialize another array with their respective telephone
numbers. Search for a name input by the user, in the list. If found, display “Search Successful” and print the name
along with the telephone number, otherwise display “Search unsuccessful. Name not listed”.
Q-1
a.
b.
c.
d.
e.
Q-2
a.
b.
c.
d.
e.
Q-3
a.
b.
c.
d.
e.
What is the difference between read() and readLine() method?
Name the api package that contain wrapper classes
Write the two ways in which you can assign a text
string”TOGETHER” to a string variable?
How can you create a package? What are user defined Packages?
What is an instance variable?
What is type casting, when do we need it ?
What do the following functions return for:
String x=”VXL”;
String y=”TutoriaL”;
(i)System.out.println(y.substring(4)+x);
(ii)System.out.println(x.indexOf(y.charAt(y.length()-1));
(iii)System.out.println(y+x.substring(5));
(iv)System.out.println(y.substring(x.length(),y.length()-3)+x.toLowerCase());
Write the equivalent switch case statement for the following decision making statement.
If(x==’1’ || x==’3’)
a=1;
if(x==’5’) a=2;
if(x==’7’) a=3
else a=10;
Explain the terms in relation to Switch
i) break
ii) case
iii) default
Write the output of following loop statement :
int a=5,b=0;
while(b<5)
{
b++;a--;
System.out.println(a+”\t”+b);
}
System.out.println(a+” HURRAY ”+b);
When is the “loss of precision” error generated?
What do you understand by the term “Escape sequence” in Java? Explain with two examples.
Distinguish between System.out.println( ) and System.out.print( ).
What do you understanding by Prefix and Postfix operator? Explain.
Write the output
System.out.print(“Earthquakes”.substring(5).charAt(3) + “ “ +“Atmosphere”.length());
Q-4. Write a program to input a number and then find frequency of digits
[15]
Q-5. Write a program that outputs the results of the following evaluations based on the Choice entered by
the
user.
[15]
v)
Check number is prime or not.
vi)
Check number is magic or not.
vii)
Check number is special or not.
Test – 4
8
Q-6.
of
Test – 4
9
Write a program that reads salesman name and their weekly sale. Prepare the list in decreasing order
weeksales. Make use of array variables. Assume week sales can be floating numbers.
Define another method that creates and print another array which stores the week sales rounded off
to the nearest integer.
[15]
Q-7.
WAP program to input a string and then
a)
Replace all the vowels by *
b)
Count no of upper case vowels
[15]
As per users choice.
Q-8.
Write a program to print the Pascal triangle following series: [15]
1
A
1 2 1
A
B
1 2 3 3 1
A B C
1 2 3 4 3 2 1
A B C D
Q-9
In a bus reservation counter the occupied seats are represented by 1 and empty seats by 0. There are
6 rows and each row has 5 seats. WAP to input status of all the seats using 1 or 0. Then enter name
of the traveler and the row no and seat no he wants. If seat is occupied print “seat already occupied”
else print “seat given to passenger name. Program should continue as long as user wants
[15]
TIME: 02.00 HRS
Paper -8
MM: 100
SECTION A (40 MARKS)
Attempt all questions
Q1.
a) Explain the significance of the term ‘Case Sensitivity’?
b) What is a constructor and how it is executed in the program?
c) Write the following array correctly:
String [a] =[a, e, i, o, u]
d) Name two non-numeric primitive data types.
e) What is the difference between a.length and a.length()? Explain giving example.
[2]
[2]
[2]
[2]
[2]
Q2.
a) Convert (x> y? x : y) into if else code.
b) What is a local variable? Mention one of its characteristics.
c) If x = 9, y = 5, determine the value of x after executing x += (++x) % y;
d) Write the difference between linear and binary search.
e) What is a package? How can you include a java package in your application?
[2]
[2]
[2]
[2]
[2]
Q3.
a) Which types of primitive data are suitable for switch expression?
b) Write the output of the following statements
1. Math.max ( Math.min (15, 25), 5)
2. ( int ) (“dreams”.charAt(2))
3. “KnOwLEDge”.indexOf(‘e’)
4. “MISSISSIPPI”.lastIndexOf(‘S’)
5. “PRESIDENT”.substring( 3, 4)
6. “APTITUDE”.compareTo(“ATTITUDE”)
[2]
[6]
c) Write the expression for the absolute value of 2 x 3 / 3 y 4
d) What a purpose is served by the keyword “this”? Give example.
[2]
[2]
Test – 4
e) Find the output
void display()
{
int a[]={2, 5, 8, 5, 3};
int i=2;
a[i] += a[i+1]++ - - -a[i-1];
for(i=1; i<5; i++)
System.out.println(a[i]);
}
g) Explain, with example, the meaning of the term “pass by value”.
10
[5]
[3]
SECTION B (60 MARKS)
Attempt any FOUR questions
The variable description is compulsory to write. Input a value through keyboard means use Buffers.
Question 4.
In order to encode messages, the principle is to shift each character or digit by two places, e.g. A to
C, B to D, . . . . . . . . , Z to B and
0 to 2, 1 to 3, . . . . . . , 9 to 1. ( assume that message is to be
converted to upper case before encoding it). Write a program in Java to do the above job inputting a
line of text from user.
[15]
Question 5.
The names and ages of thirty five students in a class are to be taken as inputs and the a print out is to
be obtained such that names and ages are printed in two columns side by side with ages in ascending
order.
Write a program in Java to do the above problem.
[15]
Test – 4
11
Question 6.
Write a program to input elements of a 3 x 3 matrix to store them. Now check whether it is a unit
matrix or not. A unit matrix is that which has 1 at its main diagonal and 0 at all other places.
Example of a unit matrix is
1
0
0
[15]
0
1
0
0
0
1
Question 7.
Using a switch statement, write a program in Java to input an amount in Indian Rupees (INR) to
convert into any of the following foreign currencies as per the given rates:
[15]
Currency
Rs (Rate/Unit)
Euro
52.87
Swiss France
34.06
Thai Baht
02.33
Yen
34.72
US$
42.28
Pound
79.39
Question 8.
Write a program in Java to accept a sentence and find out the longest word in the sentence.
[l5]
Example:
Input:
This is Human Resource Department
Output:
Department
Question 9.
In an organization, the Income Tax for employees is computed as per the following slab rates:
Slabs (Taxable Income)
Rate of Income Tax
Upto Rs 1,10,000
Nil
Rs 1,10,001 to Rs 1,50,000
10% of income exceeding Rs 1,10,000
Rs 1,50,001 to Rs 2,50,000
Rs 4,000 + 20% of income exceeding Rs 1,50,000
Above Rs 2,50,000
Rs 24,000 + 30% of income exceeding Rs 2,50,000
Write a program in Java which will accept the income of 500 people and calculate their income
Full Marks : 100
Question 1
a)
b)
c)
d)
e)
[5*2=10]
What is a ternary operator? Give its syntax.
What do you mean by implicit type conversion
How is java compilation different from ordinary compilation
Write any two rules naming variable
What do you mean type conversion? How types are their.
Question 2
a)
b)
c)
d)
e)
Time : 2 Hours
SECTION – A (40 Marks)
Attempt all questions from this section
[5*2=10]
if z=5; find x=z++*5+--z;
What is difference between indexOf(‘c’) and indexOf(‘c’,n)
Write a function on your own corresponding to Math.pow(x,4)
State difference between call by value and call by reference
Explain the significance of the return type in a function. Define word void.
Question 3
[5*2=10]
a) Math class is imported by which package ? What type of function is (member function or static )
Math.ceil().
b) What is the problem of dangling-else ? when it arise ? how can it be overridden.
Test – 4
12
c) What is default package in java?
d) An array is declared as boolean b[]= new boolean[10]; How many bits will be reserved in
memory and why ?
e) Which of the following statement executes the loop 10 times ?
[i] for(j=14 ; j<=42 ; j++) [ii] for(j=10 ; j<20 ; j=j+2)
[iii] for(j=5 ; j<=15 ; j++) [iv] All the above.
Question 4
a) Write notes of lvalue and rvalue
b) Evaluate :
If int a=3, b=5; double c=0.5
[i] a++ +b/2-++c%2
[ii] ++a-b- -+c/2
[iii] (double)(b/a)
[iv] b/(double)a
c) x=-9.99
[i] Math.abs(x)
[ii] Math.sqrt(9.0)
[iii] Math.floor(3.9)
[iv] Math.ceil(3.9)
[2]
[4*1=4]
[4*1=4]
Test – 4
13
SECTION – B (60Marks)
Question 5
a) Write a function arr_fn to store the first 9 natural numbers in an array of size 3x3.
[4]
b) Write a program to accept a number and display the highest and lowest digit of the number (
Do not use array)
[11]
Question 6
a) accept a string (in capital letter only) from the user. It is coded after adding 2
to ascii code of each character. After adding if it exceeds 90 the character will
not change. Print changed string. E.g., ABZ will be CDZ
[7]
b) Write a program to input numbers for a 2-dimentional subscripted variable with 3x3 size and
check whether it is symmetric or not. (Hints : In a square matric all elements of a(i,j) is equal
to the element a(j,i), then that matrix is called a symmetric matrix)
Question 7
a) A computer dealer sells computers at the following rates
[9]
[i] Rs.31500 per computer less than 20 computers
[ii] Rs.31000 per computer 20 to 39 computers
[iii] Rs.29000 per computer for 40 or more computers
Write a program to take the number of computer as input and display the bill. A customer gets
a further discount 15% if his dealing with the dealer for more than 5 years.
b) Write a program to calculate and print the value of z=(x*x+y*y)/(x+y) where x ranges from 0
to 50 and y as a constant 0.05 (make use of a user defined function)
[6]
Question 8
a) Write a method to print the sum of positive numbers and sum of negative numbers from a list
of numbers entered by the user. The processes terminate whenever the user enter a zero.
[10]
b) If an array contains in a 3x3 elements as follows :
{{1,2,3},{4,5,6},{7,8,9})
Display the rotated matrix by 90 degree left and the outputs are as follows:
369
258
147
Question 9
[15]
Write a programe to find the area of circle (∏r2) where ∏=22/7 and r is the radius, rectangle (l*b)
where l and b are the two sides of the rectangle or a triangle
(s*(s-a)*(s-b)*(s-c)) where a,b and c are the three different sides and s=(a+b+c)/2 as per user’s
choice. In case of a triangle if the sum of two sides of the triangle is not greater than the third side
then the triangle does not exist.
Section – I (40 Marks)
( Class : X )
( Two Hours)
Q1. a) Differentiate between pure and impure functions.
b) What is friendly access of class members?
c) What is Data Abstraction?
d) How is a ordinary compilation process different from Java compilation?
e) Name four packages available in Java?
[10]
Q2. a) What is an exception? What is exception handling?
b) Differentiate between pure and mixed expression.
c) What is type casting?
d) What is the use of [ ] and ( ) operator ?
e) What do you mean by rvalue and lvalue?
[2]
[2]
[2]
[2]
[2]
Q3. a) Write the corresponding Java expressions for the following: [4]
i) 2 - ye2y + 4y ii) 5a + b (x + y )5
b) Suppose A,B,C are integer variables where A = 3, B = 3, C = 5 and X,Y,Z are the floating point
Test – 4
14
variables where X = 8.8, Y = 3.5, Z = -5.2. Determine the value of the following expressions :
i)
ii)
iii)
iv)
v)
A%C
(A*C)%B
X / ( X+Y )
X/Y
(int) X % (int) Y
c) Name the library function used to compare two strings according to ASCII code
Q4. a) State the final value of q at the end of the following program segment:
int m, n , p, q = 0;
for (m = 2; m <= 3; + +m )
{
for (n = 1; n <= m; + +n )
{
p = m + n – 1;
if ( p % 3 = = 0)
q + = p;
else
q + = p + 4;
}
}
b) What will be the output of the following code:
import java.io.*;
public class a
{
public static void main( String args[ ] ) throws IOException
{
byte x = 65;
char y;
y = (char) (x++);
System.out.println( y);
}
}
c)
import java.io.*;
public class a
{
public static void main( String args[ ] ) throws IOException
{
int n;
for (n = 5; n != 7; ++n )
system.out.println( n);
}
}
d) For a multidimensional int array X[2][10], find the number of bytes required.
[5]
[1]
[5]
[2]
[2]
[1]
SECTION B ( 60 Marks )
Q5. Write a program to compute charges for sending parcels where the charges are as follows :
For the first 1 kg Rs. 25.00
For additional weight for every 500 gms or fraction thereof Rs. 10.00
[15]
Q6. Write a program to declare an array of 500 integers and get the numbers from the user. Sort the array
in descending order using Bubble sort method. Display the sorted array.
[15]
Q7. You are given a list of marks on n students ( n <=100). These are already stored in an array in descending order
of value and there are no duplicates eg.
N=6
Marks
99
87
76
75
74
65
Write a program that allows a user to input the marks and determine if it is present in the list. If the
Test – 4
15
marks are present output its position in the list otherwise output the message “Sorry, Not present in the list”.
Use the Binary Search technique. Repeat the search for different values as long as user wishes to
continue.
[15]
Q8. Write a program for the following :
a) To print the series 2, 5, 10, 17, 26 …………..up to 10 terms.
b) To calculate the sum of the given series
S = 1 + ( 1+2) + (1+2+3) +………………+ (1+2+3+…….+20)
[15]
Q9. Design class Bank with the following descriptions :
Data members :
name : to store the name of the depositor
acno : to store the account number
type : to store type of the account
bal : to store the balance amount in the account
Member functions :
Bank( ) : constructor to assign the data members as 0 or null
depo( ) : to deposit an amount
withdraw( int ) : to withdraw an amount after checking the balance
( Minimum balance should be Rs. 500 )
print( ) : to print the all the details
[15]
Q10. Write a program to create two 3 * 3 matrix( A and B ) and input the numbers from the user.
Now do the following:
iv)
Create another matrix C of 3*3 and store the sum of corresponding elements from A and B.
v)
Find the Minimum value in matrix C and its position in the array.
[15]
Q-1
f) if z=5; find x=z++*5+--z;
g) What is difference between indexOf(‘c’) and indexOf(‘c’,n)
h) Math class is imported by which package ?
What type of function is (member function or static ) Math.ceil().
i) What is default package in java?
j) An array is declared as boolean b[]= new boolean[10]; How many bits will be reserved in memory
and why ?
Q-2
a) Which of the following statement executes the loop 10 times ?
[i] for(j=14 ; j<=42 ; j++)
[ii] for(j=10 ; j<20 ; j=j+2)
[iii] for(j=5 ; j<=15 ; j++)
[iv] All the above
b) Evaluate :
If int a=3, b=5; double c=0.5
[i] a++ +b/2-++c%2
[ii] ++a-b- -+c/2
[iii] (double)(b/a)
[iv] b/(double)a
c) x=-9.99
[i] Math.abs(x)
[ii] Math.sqrt(9.0)
[iii] Math.floor(3.9)
[iv] Math.ceil(3.9)
d) What is a constructor and how it is executed in the program?
e) Write the following array correctly: String [a] =[a, e, i, o, u]
Q-3
a) Name two non-numeric primitive data types.
b) If x = 9, y = 5, determine the value of x after executing
c) Write the output of the following statements
1. Math.max ( Math.min (15, 25), 5)
2. ( int ) (“dreams”.charAt(2))
x += (++x) % y;
Test – 4
16
3. “KnOwLEDge”.indexOf(‘e’)
4. “MISSISSIPPI”.lastIndexOf(‘S’)
5. “PRESIDENT”.substring( 3, 4)
6. “APTITUDE”.compareTo(“ATTITUDE”)
2x3 / 3y 4
d) Write the expression for the absolute value of
e) What a purpose is served by the keyword “this”? Give example.
Q-4
a) Find the output
void display()
{
int a[]={2, 5, 8, 5, 3};
int i=2;
a[i] += a[i+1]++ - - -a[i-1];
for(i=1; i<5; i++)
System.out.println(a[i]);
}
b) What is the difference between read() and readLine() method?
c) Name the api package that contain wrapper classes
d) Write the two ways in which you can assign a text
string”TOGETHER” to a string variable?
e) What do the following functions return for:
f)
Q-5
String x=”VXL”;
String y=”TutoriaL”;
(i)System.out.println(y.substring(4)+x);
(ii)System.out.println(x.indexOf(y.charAt(y.length()-1));
(iii)System.out.println(y+x.substring(5));
(iv)System.out.println(y.substring(x.length(),y.length()-3)+x.toLowerCase());
Write the output of following loop statement :
int a=5,b=0;
while(b<5)
{
b++;a--;
System.out.println(a+”\t”+b);
}
System.out.println(a+” HURRAY ”+b);
Test – 4
17
Q-6
Write a program to accept the names of 10 cities in a single dimension string array and their STD
(Subscribers Trunk Dialing) codes in another single dimension integer array. Search for a name of
a city input by the user in the list. If found, display “Search Successful” and print the name of the
city along with its STD code, or else display the message “Search Unsuccessful, No such city in
the list”.
Q-7
Input 100 numbers in array and sort them in descending order using selection sort
Q-8
Using the switch statement, write a menu driven program:
(i) To check and display whether a number input by the user is a composite number or not (A
number is said to be a composite, if it has one or more than one factor excluding 1 and the number
itself).
Example: 4, 6, 8, 9...
(ii) To find the smallest digit of an integer that is input:
Sample input : 6524
Sample output : Smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.
Question 1.
[10]
a) Name any two library packages.
b) State two main features of an Object Oriented Programming language.
c) Show the use of logical operator && with an example.
d) Name the library function used to compare two strings according to ASCII code
e) What is a ternary operator? Give its syntax.
Question 2.
a) if z=5; find x=z++*5+--z;
b) What is difference between indexOf(‘c’) and indexOf(‘c’,n)
c) Math class is imported by which package ?
What type of function is (member function or static ) Math.ceil().
[10]
Test – 4
18
d) An array is declared as boolean b[]= new boolean[10]; How many bits will be reserved
in memory and why ?
e) What is a constructor and how it is executed in the program?
Question 3.
[20]
a) x=-9.99
[i] Math.abs(x)
[ii] Math.sqrt(9.0)
[iii] Math.floor(3.9)
[iv] Math.ceil(3.9)
b) Evaluate : If int a=3, b=5; double c=0.5
[i] a++ +b/2-++c%2
[ii] ++a-b- -+c/2
[iii] (double)(b/a)
[iv] b/(double)a
c) What is a local variable? Mention one of its characteristics.
d) If x = 9, y = 5, determine the value of x after executing
x += (++x) % y;
e) Which types of primitive data are suitable for switch expression?
f) Write the output of the following statements
1. Math.max ( Math.min (15, 25), 5)
2. ( int ) (“dreams”.charAt(2))
3. “KnOwLEDge”.indexOf(‘e’)
4. “MISSISSIPPI”.lastIndexOf(‘S’)
5. “PRESIDENT”.substring( 3, 4)
6. “APTITUDE”.compareTo(“ATTITUDE”)
Test – 4
19
Question 4.
Define a class Book Store having the following specifications:
Data Member: Name of the book, author, publication and cost.
Member Methods:
(i) To accept the book details
(ii) To calculate the discount of 13.5% given on all books.
(iii) To display the book details.
Using a main method and an object. call the above methods
Question 5.
Write a program in Java to accept a string and display the new string after removing all the vowels
from the string.
Sample Input: Computer Applications with BlueJ
Sample Output: Cmptr pplctns wth BlJ
Question 6.
A class Sort contains an array of 50 integers. Some of the member functions/data members are
given below: Class name : Sort
Data members/instance variables
arr[] integers
item number to be searched for in the array
Member functions/methods
void inpdata() to input 50 integers.
void bubsort() to sort the array in ascending order using the bubblesort technique and to display
the sorted list.
void binsearch() to input item and search for it using the binary search technique, if found to print
the item searched and its position in the sorted list, otherwise to print an appropriate message.
Specify the class Sort giving the details of the functions void inpdata(), void bubsort() and void
binsearch(). The main function need not be written.
Question 7.
Write a program that outputs the results of the following evaluations based on the Choice entered
by the user.
viii)
Check number is prime or not.
ix)
Check number is magic or not.
Question 8.
Design a class to overload a function area() as follows:
(i) double area(double a, double b, double c) with three double arguments and
returns the area of a scalene triangle using the formula:
area = √ s(s – a)(s - b)(s - c) where s = (a+b+c) / 2
(ii) double area(int a, int b, int height) with three integer arguments
Test – 4
and returns the area of a trapezium using the formula:
area = 1/2 * height(a+b)
(iii) double area(double diagonal1,double diagonal2) with two double arguments
and returns the area of a rhombus using the formula:
area = 1/2 (diagonal1 * diagonal2)
Q-1
i) Write a statement to create an object named act of the class Action that invokes a
parameterized constructor that takes 2 byte type values.
ii) String x[] = {“Welcome”,”Bye”};
a) What is x.length
b) What is x[1].length
iii) Write a statement to print the character at index 5 in the string str.
iv) What is a constructor? What is the return type of the constructor?
v) Write prototype of the function that return true / false and takes two characters as
parameter.
Q-2
i) Initialize a character array with 5 vowels.
ii) Name the java package that contains the class Math and String
iii) Name the wrapper class for char and Boolean
iv) Write a statement to declare an array with 35 real numbers.
v) Name the primitive datatypes that represents integers.
Q-3
i) Write a statement using library function to :
a. Check if the character is a digit and store the result in variable var.
b. Find larger of two integers a and b
ii) Name the keyword
a. Used to invoke the package in our class
b. Used to allocate memory
iii) Give Outputs
a. Math.ceil(-8.9)
b. Math.floor(3.5)
c. Math.round(4.6)
d. Math.max(8.5,13.5)
e. Math.rint(6.5)
f. Math.abs(-22.33)
iv) Write a statement to call a function named trial that takes 1 string and 1 char values and
returns true or false
Q-4
i) Find Outputs
1. Math.max ( Math.min (-8.9,9.8), 5)
2. ( int ) (“education”.charAt(1))
3. “clever”.indexOf(‘e’)
4. “COOPERATE”.lastIndexOf(‘O’)
5. “PRESIDENT”.substring( 3, 4)
6. “BANGKOK”.compareTo(“AMERICA”)
ii) If x = 12, y = 7, determine the value of x after executing
x += (++x) % y;
iii) Name the API package that contain wrapper classes
iv) What do the following functions return for:
String x=”JAVA”;
String y=”PROGRAMMING”;
(i) System.out.println(y.substring(4)+x);
(ii) System.out.println(x.indexOf(y.charAt(y.length()-1));
(iii) System.out.println(y+x.substring(5));
20
Test – 4
21
(iv) System.out.println(y.substring(x.length(),y.length()-3)+x.toLowerCase());
v) Write the output
System.out.print(“Earthquakes”.substring(5).charAt(3) + “ “ +“Atmosphere”.length());
Q-5
WAP to find whether the number is
a) Perfect number or not
b) Prime number or not
as per users choice
Q-6
Q-7
WAP to perform binary search on 50 integers
Write a class overload to write the following functions
i)
void num_calc(int n, char ch) with one integer argument and one character
argument, computes the square of integer argument if choice ch is ‘s’ otherwise finds
its cube.
ii)
void num_calc(int a, int b, char ch) with two integer arguments and one character
argument. It computes the product of integer arguments if ch is ‘p’ else adds the
integers.
iii)
void num_calc(String s1, String s2) with two string arguments, which prints larger of
two strings according to asci code.
Q-8
Write a program to accept a word and convert it into lowercase if it is in uppercase, and
display the new word by replacing only the words with the character following it.
Example
Sample Input : computer
Sample Output : cpmpvtfr
Q-9
WAP to input a string and print only those words that start and end with a vowel
Q-10 Create a class Search
Data members/instance variables
array containing 5 names
array containing 5 surnames
item : name to be searched for in the array
Member functions/methods
void inpdata() to input array values
void linear() to input item and search for it , if found then print name and surname
otherwise to print an appropriate message.
Also write main function.
© Copyright 2026 Paperzz