0% found this document useful (0 votes)
76 views4 pages

La Martiniere For Boys, Kolkata - Answer

The document outlines a rehearsal examination for La Martiniere for Boys, Kolkata, covering various topics in Java programming and object-oriented principles. It includes multiple-choice questions, coding tasks, and programming exercises related to classes, methods, and algorithms. The examination is structured into two sections, with Section A focusing on theoretical questions and Section B requiring practical coding solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views4 pages

La Martiniere For Boys, Kolkata - Answer

The document outlines a rehearsal examination for La Martiniere for Boys, Kolkata, covering various topics in Java programming and object-oriented principles. It includes multiple-choice questions, coding tasks, and programming exercises related to classes, methods, and algorithms. The examination is structured into two sections, with Section A focusing on theoretical questions and Section B requiring practical coding solutions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LA MARTINIERE FOR BOYS,KOLKATA

REHERSAL EXAMINAITON 2024-25


Section-A Answer all questions
Q.1.Choose and write the correct answer:-(1X20=10M)
1.When we pass an array to a method, the method receives-(the length of an array,a reference of the array,a copy of the
array,each of the elements of the array)
2.Which principle of OOP is used for hiding unnecessary details from the external world.
(encapsulation,inheritance,abstraction,polymorphism)
3.The range of ASCII values of the lower case letters lies in the range of-(47 to 58,65 to 90,97 to 122,97 to 121)
4.What will be the result of x%y, if the value of x=5 and y=2(1,0,1.0,-1)
5.A sequence of statements enclosed within matching pair of curly braces is known as-(null statement,void
statement,compound statement,empty statement)
6.Which of the following is an empty loop-(for(i=0;i<6;i++);,while(i<5)i++;,do{i++;}while(i<6);,none of the above)
7.What will be the output of the following Java statement:-System.out.println(“HE”.compareTo(“HELLO”));(-3,2,5,-2)
8.What will be the output of the following Java statements:-int arr[][]={{1,2,9},{1,2,3},{1,6,1}} System.out.println(arr[1].lenth);
(error,3,2,0)
9.What is the prerequisite for performing binary search on an array-(The array must contain number of elements,the array must
contain even number of elements,the element to be searched should either be placed in the beginning or at the end of the
array,the array must be sorted)
10.What will be the output of the following code System.out.println(“DEDICATED”.indexOf(‘D’,2));(0,7,2,-1)
11.Name the package of which the String class is a part of-(java.Math,Java.lang,Java.util,Java.io)
12.What is the use of the following escape sequence \n-(inserts a tab,inserts a null character,inserts the character n,inserts a
newline)
13.

variable methods

Name the feature of java depicted in the above picture.(polymorphism,encapsulation,abstraction,parametrised constructor)


14.Assertion(A)Java programs can run on any platform that has the corresponding JVM installed in it.
Reason(R) Java is a platform independent programming language. .( Both (A) and (R) are true and (R) is a correct explanation of
(A),Both (A) and (R) are true and (R)is not correct explanation of (A),(A) is true and (R)is false,(A) is false and (R) is true)
15.Assertion(A)-Static data members do not require to be invoked by an object
Reason(R)-Only one copy of the static variable is created and is shared by all the objects of the class. .( Both (A) and (R) are true
and (R) is a correct explanation of (A),Both (A) and (R) are true and (R)is not correct explanation of (A),(A) is true and (R)is false,
(A) is false and (R) is true)
16.What will be the output of the following Java code-System.out.println(:Dedicated”.endsWith(‘D’));(false,logical
error,true,syntax error)
17.What will be the value of , if a=5, b=7; k=--a*b++ + b%--a + a; (33,37,41,44)
18.Read the following text and choose the correct answer:-
Mr.Srinivasan, a renowned programmer wants to use a property where in he intends to access the data members of one
class from another class. Which property of an OOP does he intend to use?(constructor overloading,method
overloading,encapsulation,inheritance)
19.Which of the following components is contained in the BlueJ environment.(code editor,debugger,terminal,all of the
above)
20.Which of the following is a relational operator.(==,|,&&,+)
Q.2.
1.Write the Java statement for the following expression:- √ ax + y double p=Math.sqrt(a*x+y);
2.Evaluate the expression when the value of k=5 k-=--k + k++ * --k; -15
3.The following code should print the letters A to Z in Uppercase. However the code has some errors.Fix the code so
that it compiles and executes correctly.
for(int i=65;i=87;i++){char ch=i;System.out.println(ch);}
char ch;for(int i=65;i<=87;i++){ ch=i;System.out.println(ch);}
4.State any two keywords used within the switch block. case,break
5.Predict the output:-
String str=”COMPUTER”;String str1=”PROGRAM”;String
str2=str.substring(2,7)+Integer.toString(str1.indexOf(‘r’,1));System.out.println(str2); MPUTE-1
6.How many times will the loop execute and what will be the output:- 25 4 times
int k=5,i=1; while(i++<9){k+=i++;}System.out.println(k);
7.Consider the two arrays:-
int a[]={1,2,3,4,5}; int b[]={5,4,3,2,1}; What will be the output:-double
m=Math.round((int)Math.sqrt(a[1]+Math.sqrt(b[1])*Math.min(a[3],b[2])));System.out.println(m); 2.0
8.When there is no explicit initialization, what are the default values set for variables in the following cases?i)booean
Variable-false ii)character variable-\u0000
9.State one point of difference in the use of the statements break-terminates the loop and System.Exit(0)-terminates the
program.
10.Ramesh tries to execute the following program segment to find out the area of a circle. However the output is
obtained is incorrect. How the program can be modified to get the correct answer? Also state the type of error made by
Ramesh. double radius=8.9;double pi=3.14;int area=pi*Math.pow(radius,2);System.out.println(area); syntax error
double radius=8.9;double pi=3.14;double area=pi*Math.pow(radius,2);System.out.println(area);
SEC-B
Answer any four questions from this section:-Each program should be written using variable description and
comment lines.
Q.3.An electricity board of a state has revised its tariff as per the following criteria.
Design a class ElectricTariff with the following specifications:-
Class name: ElectricTariff Member variables:- name-to store the name of the customer units-to store the units
consumed amount –the final amount to be paid by the customer.
Member functions-
ElectricTariff()-default constructor to initialize he member variables with default values.
void accept()-to accept the name and the number of units consumed.
void calculate()-to calculate the amount to be paid as per the following criteria:-
Number of units consumed Amount to be paid(in Rs.)
First 100 units 100
Next 100 units 0.5 per unit
Next 100 units 1.5 per unit
Next 100 units 2 per unit
Above 400 units 2.5 per unit
However a GST of 7.5% has to be added to the final bill.
void display()-Displays the name,units consumed and the amount to be paid by the customer.
Write a main method to create an object of the class and call the above functions.
import java.util.*;
class ElectricTariff{String name; int units;double amount;
ElectricTariff(){name=” “;units=0;amount=0.0d;}
void accept(){Scanner br=new Scanner(System.in);System.out.println(“Enter Values”);
name=br.nextLine();units=br.nextInt();}
void calculate(){if((units>=1)&&(unuits<=100))amount=100;
else if((units>100)&&(units<=200))amount=100+(units-100)*0.5;
else if((units>200)&&(units<=300))amount=100+(100*0.5)+(units-200)*1.5;
else if((units>300)&&(units<=400))amount=100+(100*0.5)+(100*1.5)+(units-300)*2.0;
else amount=100+(100*0.5)+(100*1.5)+(100*2.0)+(units-400)*2.5; amount=amount+(amount*7.5/100.0);}
void display(){System.out.println(name+” “+units+” “+amount);}
public static void main(){ElectricTariff ob=new ElectricTariff();ob.accept();ob.calculate();ob.display();}}
Q.4.WAP to accept the year of world cup cricket as an integer value from the user.Using the binary search technique on
the sorted array of integers given below, print the name of the winning team if the value input is located in the array. If
not, print the message “Record does not
exist”.{2023,2019,2015,2011,2007,2003,19999,1996,19992,1987,1983,1979,1975}{“Australia”,”England”,
“Australia”,”India”, “Australia”, “Australia”, “Australia”,”Sri Lanka”,”Pakistan”, “Australia”,”India”,”West Indies”,”West
Indies”}
import java.util.*;
class bi
{public static void main(){Scanner br=new Scanner(System.in);
int a[]={2023,2019,2015,2011,2007,2003,19999,1996,19992,1987,1983,1979,1975};
String b[]={“Australia”, ”England”, “Australia”, ”India”, “Australia”, “Australia”, “Australia”, ”Sri Lanka”, ”Pakistan”, “Australia”,
”India”, ”West Indies”, ”WestIndies”};
System.out.println(“Enter a year”);int n=br.nextInt();
int flag=-1,l,u,m=0;
l=0;u=13;
while(l <=u)
{m =(l+u)/2;
if (n >a[m])
l=m+1;
else if(n <a[m])u=m-1;
else
{flag=m;
break;}}if (flag>-1)
System.out.println(a[m]+” “+b[m]);
else
System.out.println("element not present");}}

Q.5.Write a menu driven program using switch case to:-


1-Input a string in uppercase and display the first letter of every word.
2-Input a word, convert to uppercase and form a new string to shift all the consonants of the word at the beginning
followed by the vowels. Print the formed string. E.g.APPLE becomes PPLAE
For an incorrect choice,display an appropriate message.
Q.6.Design a class to overload the method print as follows:-
void print(String a)-to display the following pattern using nested loop e.g. if a=”COMPUTER” prints
COMPUTER
OMPUTER
MPUTER
UTER
TER
ER
R
void print(int n)-to check if the number is a sapphire number or not.A sapphire number is a number which is 1 less than
the cube of any number. For example 7,26,999 are sapphire numbers.Display a suitable message accordingly.
class pr
{void print(String a)
{int i;
for(i=0;i<a.length();i++)
{System.out.println(a.substring(i));}}
void print(int n){ int i,c=0;
for(i=1;i<n;i++)
{ if((i*i*i-1)==n)
{System.out.println(n+"Sapphire number");System.exit(0);
}}
System.out.println(n+"not Sapphire number");}}
Q.7.WAP to accept the names of 10 cities in an array.Sort the names in alphabetical order.Display the sorted array.
import java.util.*;
class bubble
{public static void main()
{Scanner br=new Scanner(System.in);
String a[]=new String[10];
int i,j; String t=" ";
for(i=0;i<10;i++)
{System.out.println(“Enter values”);
a[i]=br.nextLine();}
for(i=0;i<10;i++)
{for(j=0;j<10-i-1;j++)
{if(a[j].compareTo(a[j+1])>0)
{t=a[j];
a[j]=a[j+1];
a[j+1]=t;}}}
System.out.println("Ascending order");
for(i=0;i<10;i++)
{ System.out.println(a[i]);}}}
Q.8.Design a class to accept elements into a 4X4 array, check and print if it’s a sparse matrix or not.A sparse matrix is a
matrix in which most of the elements are zero.
0030
0008
1030
0070
import java.util.*;
class table
{public static void main()
{Scanner br=new Scanner(System.in);
int a[][]=new int[4][4];
int i,j,s=0;
for(i=0;i<4;i++)
{for(j=0;j<4;j++){System.out.println(“Enter values”);a[i][j]=br.nextInt();
if(a[i][j]==0)s++;}}
if(s>8) System.out.println(“sparse matrix”);
else System.out.println(“Not sparse matrix”);}}

___________________________________ALL THE BEST __________________________________________

You might also like