Preboard Computer Science. 2024
Preboard Computer Science. 2024
SECTION A
(Attemptall questions from this Section.)
Question 1
Choose the correct answers to the questions from the given options. (Do not copy the question, write the
Vehicle
X
(yele
Car Truck
(a) Encapsulation
(b) Inheritance
(c) Abstraction
(d) Polymorphism
(a) ternary
(b) unary
(c) logical
(d)relational
used to accept words with space:
(ii) The Scanner class method
(a) next()
(b) nextLine()
(c) Next()
(d) nextString( )
(a) continue
(b) break
(c) return
(d) System.exit(0)
(a) 20 bytes
(b) 60 bytes
(c) 40bytes
(d) 120 bytes
System.out.println();
(a) finite
(b) infinite
(c) null
(d)fixed
a char:
integer argumentand returns
check() which takes an
(vii) A method prototype name
(a) char check()
(b) 16.0
(c) 17.0
(d) 16
Page 2 of 10
iN) Predict the output of the following code snippet: String P="20", Q="22";
int a = Integer.parselnt(P);
(a) 20
(b) 20 22
(c) 2220
(d) 22
(c) 4 bits
(d) bits
16
(xi)The output of the function "COMPOSITION".substring(3, 6):
(a) POSI
(b) POS
(c) MPO
(d) MPOS
(a) implicit
(b) automatic
(c) explicit
(a) java.lang
(b) java.util
(d) java.awt
Page 3 of 10
i as:
is termed
of variables
value
method which does not modifythe
(xiv) A
(b)pure method
1. 4
2 4.0
3 4.3f
4 "four
(a) Only I.
(b) 1. and
3.
(c) 2. and 4.
(d) 1. and 2.
true
(a)
(b)
(c)
(d) false
Assertion (A) - We should not give the same name to two identifiers even if the
b) Both A and R are true but R is not the correct explanation ofA
Page 4 of 10
): In Java, statemlens
Assertion(A
xvii)
are treated as the same.
Assertion (A) of
c) Assertion (A) is
a)24
b)23
c)20
d)25
to perform
be used in our program
are the built-in modules that can are used for specific
functions.
(xx) Functions that
are some mathematical functions
There
a specific operation. square root of a positive
function to return return
we can use Math.sqrt() and Math.ceil() to
For example, number in a range of numbers
random
number, Math.random() to return
number.
the next higher integer
is executed?
be displayed, if the following statement
What will
(Math.sqrt(-25);
System.out.printIn
Infinite
a)
b) -5.0
c) NaN
d) Logical error
Page 5 of 10
ot
output
the
Write"MANAGE
ví)
a) ""science".c
b)
Question 2
any
t
Name
vii)
i) Write the Java expression for : ab + (2a - (b')
12)
ii)The following code segment should print the sum ofodd factors of a +ve number N. However the code
has errors. Nanme the error and fix the code so that it compiles and runs correctly.
(2]
void odd Fact(int N)
boolean oddf-false;
int i-2,sum;
while(i<=N)
oddf-(N%i==0 i%2==1)?true:false:
|
|
if(oddf)
sumt-i;
itt;
System.out.println("'Sum="+sum);}
iv) The following code segment should print the last four characters ofa word if the length of the word is
even otherwise it will display first four characters of the same word. However the code has errors. Fix the
string wd="COMPUTER":
if(wd.length % 2==0)
System.out.printin(wd.substring(4));
else
System.out.printIn(wd.substring(0,3));
int callme){
int x=2,y=40;
do
c+t;
x+=x+t;
y--x++ % --y;
}while(x<y);
return X+y;
Page 6 of 10
vi) Write the output ofthe following code segments: (2]
a)
"MANAGE".compareTo("MANAGEMENT")
b) "science".charAt(3)+india".lastIndexOf('i')
vii) Name any two keywords in JAVA used as default value to initialize instance data membersof a class.
(2)
vii) Predict the output of the following code snippet:(Show dry run) (2]
void outputX)
{
int x=5,y-8;
while(t+-+x<y--)
{
if(xty<15)
x+=x+t
if(y%3!=0
y--y % x;
|
+ 7/5/3:
x!=y+2)
System.out.printin("Value="+xty);
System.out.printin("Final Value="+xty);
ix) What is the need of Wrapper class in Java? Write any one method prototype of Character class.
(2]
(2)
third array C[).
Page 7 of 10
B
SECTION this Scction.)
from
any four
questions or any program
(Answer environment
Bluel
in either
of the programs of the
consist the base logic
should as thatthe
in this section
codes so
with java
The answers environnment
description
/mnemonic
using variable
be written
Each programshould is clearly
depicted.
program not required.
are
and algorithms
Flowcharts
guéstion
3
description:
having the following
taximeter
Define a class
variables
Data members/instance
passenger's
name
name - to store
String
kilometres travelled
km to store number
of
int -
Member functions:
to initialize the data members
taximeter)-- constructor
be positive)
String ), name(String) and ,km(must
input) - tostore taxino(
Rate/km
(km)
Rs 25
Up to 1 km
Rs 10
Next 5 kms
Rs 15
Next 6 km
Rs 20
Next 6 km
>18 km
Rs 25
Page 8 of 10
4:
Ouestion
QMestion 5
Expected Ouiput:
Original string:
abcdesdfafbccb
uestion 6
Write a program to accept the weight of N persons in an array. Sort the
array in descending order using
selection sort logic . Print both the original and sorted array. Now find the
average weight and print the
number of persons who weigh less than the average weight. [15]
Instance variable
N:No. of persons
Weight(int no) :
Constructor to assign N by no and allocate memory for the array
Wts():calculate and display average weight()and print the number of persons who weigh less than the
show
average weight.
Page 9 of 10
Question 7
Required matrix:
10 12 30
20 40 11
30 10 12
It is a special matrix (As you can see that sum of elements of row and
1 3 row(last row) is 52).
|15]
Question 8
Define a class to overload the method check as
follows:
[15]
void check(String str)print the vowels and consonants in alternative order. It will start either with
vowel or consomant as it is present in the string.The remaining vowels or consonants will be added at
the end.Assume str is taken in capital letter
Input : "0CCURRENCE"
Output : “0CUCERERNC"
Page 10 of 10