Vms X Preboards Computer
Vms X Preboards Computer
(ii) Arrange the following java statements in the correct order of execution to swap the
values between the two variables a, b.
() a=a-b; (ii) b=a-b; (ii) a= a+b;
(A)), (), (ii) (B) (),(1), (ii) (C) (i), (i),() (D) (ii),(),(1)
(i) Raj wanted to count the number of digits in agiven number without using aloop. Which of
the following statements is correct to perform the above?
(A) String valueOf(n).length (B) String.valueOf(n).length()
(C) Integer.parseInt (n).length() (D) n.length
(iv) Which of the following String methods have at least one integer argument?
() length0 (ii) charAt) (iii) substring0 (iv) indexOf0
(A) (i), (ii) .(iv)
(B) (11), (ii)
(C) (i).(iv)
(D) Allof the above
1
(v) Which of the following is true about java Strings?
(A) Strings are mutable.
(B) Strings can contain only letters.
(C) Strings are implemented as array of characters.
(D) All of the Above
(vi) What is the output of the following code snippet?
int k= 0;
for(; k< 5; k++){
if (k> 2) continue ;}
System.out.printin(k);
(A) 5 (B) 0 (C) 4 (D) Compilation Error
(vii) Find the value of a[1] after execution of the following program.
int] a = {0,2,4,1,3}:
for(int i = 0; i <a.length; i++)
a[i]=a[(a[] +3) %a.length];
(AJ0 (B)1 (C)2 (D)3
(ix) When an object of a Wrapper class is converted to its corresponding primitive data type,
it is called as
(A)Boxing (B) Explicit type conversion ()Unboxing (D)Implicit type conversion
(x) % operator can be applied to
(A) Integers (B) Floating-point numbers (C)Characters (D) All of these
(xi)double x = 6.2;
if(x-- >= 6.0)
System.out.print("irst "):
if(-x >= 5.0)
System.out.print("'second ");
if(X-- >= 4.0)
System.outprint("third ");
else
System.out.print("fourth ");
(A)first second third (B) first second fourth (C)first fourth (D)irst third
(xii)Assertion:Abstraction is the process of exposing the implementation of an object.
2
Abstraction allows you to focus on what an object task. It
does rather than how it is doing the
helps in managing complexity.
A) Both Assertion and Reason are true and Reason is a correct explanation of Asserton.
(B) Both Assertion and Reason are true and Reason is not a correct explanation of Asserdou.
(C)Assertion is true and Reason false
(D)Assertion is false and Reason ftrue
(xii) Find the output/Error of the following code.
int ++a = 100;
System.out.println(++a);
(A) 101 (B) Compilation error (C) 100 (D)102
(xiv) Find the output/ Errorof the following code.
for(int i =0; i<5; i=5 )
System.out.print("Hello");
(A)"Hello" will be printed 5 times (B) "Hello" will be printed 4 times
(C) Compilation Error (D) "Hello" will be printed 1time
(xv) Identify the modifier which cannot be used for constructor.
() public (1) protected (ii)private (iv) static
(A) Only (ii) (B) (ii) .(iv) () (), (i),(iv) (D) Only (iv)
(xvi)
private
default
protected
public
3
(x0x) The output of the statement Math.ceil(-0.6) +Math.round(-4.5) is
(A) -5.0 (B)-4.0 (C) -3.0 (D) -2.0
(xx) Name the method depicted in the following picture :
6 1 8 5
1 ocollcol L 5
1 5
1 6 5
1 6 5 8
(A)Selection Sort (B) Bubble Sort (C) Linear Search (D)Binary Search
Question 2: [10x2=20]
(iv) Convert the following statements into switch case (where O<=n <=100 ):
int n=65;
if (n>= 80)
System/out/printin("Grade A");
else if (n >= 50)
System/out/printin("Grade B");
else
System/out/println("Fail");,
(v) Find the output of the following code snippet:
String Mystr="No@1", newstr="" ;
int count=0;
for(int i=0; i<Mystr.length 0; i++)
{if (count%2 != 0 )
newstr= newstr+count;
else
if(Character.isLowerCase(Mystr.charAt()) )
newstr=newstr + Character.toUpperCase (Mystr.charAt()):
else
newstr=newstr+ Mystr.charAt(i);
count+=1;
)
System.out.printin(newstr) ;
4
Find the output :
System/out/printin("COMPUTER"/charAt(6])+ "COMPUTER"/indexOf(Z)
+ "computer"
/compareTo ("com"));
(i) within
(a)writetheajava statement to print the index of the second occurrence of the letter'1
word "MICHIGAN".
(b) Find the output:
System]out/printin("Rocket")substring(0,4)/compareTo("Rocket"/replace (m''o)}
(vii) Akash has written the following code. It is written to check whether a string is palindrome or
not. However the code is not giving the desired result when parameter is passed to tne
method isPalindrome(. Analyse the following code and answer the following questions:
boolean isPalindrome(String s)
while(true){
if (s.length)>1) return true ;
else if (s.charAt(0) != s.charAt(s.length) -1 )) return false;
S= S.substring(0, s.length -1);
}
Group- B( 60 Marks)
(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 deseription / mnemonic
codes so that the logic of the program is clearly depicted.
5
Question 3
Define a class Employee with the following :
Class name: Employee
Data Member:
String pan : to store personal account no
String name :to store name
double income: to store annual income
double tax :to store tax that is calculated
Member functions:
void input) : input data members except tax
void cal): calculate tax on annual income on the tax slab given below
void display0 : display the data members
Employee compare(Employee): compare tax between current object and parameterized object and
return the object whose tax is more.
void main0 :create two objects and display the details of the Employee whose tax amount is greater.
Income Tax Slab Tax Rate for Individual
0 to 2,50,000 Nil
2,50,001 to 5,00,000 5% of annual income exceeding 2,50,000
5,00,001 to 10,00,000 12,500 + 20% of annual income exceeding5,00,000
Above 10,00,000 30,000 + 30% of annual income exceeding 10,00,000
Question 4 [15]
Create a class Potential with the following details:
Class Name:Potential
Data Member:
sent:to store asentence in uppercase
Member functions:
Parameterized constructor to initialize the data member.
int calculate(String w): Calculate and return the potentialof a word.
The encryption of letters is to be done as follows:
A=1
B=2
C=3...
Z= 26
The potential of a word is found by adding the encrypted value of the letters. Example: LOOK
Potential =12 + 15+ 15+11 =53
Ouestion6 [15]
opposite case then
() Write a program to input a word and decode it by replacing each letter into
by the next character in a circular way. e.g. AbZ will be bCa
odd or not. If it is odd
() Write a program to input a word in uppercase and check its length is
then print the following pattern.
For the word "CROWN" the pattern will be.
ROW
CROWN
[15]
Question7
in ascending order. Inputa
Write aprogram to initialize an integer array of size 6 where the elements are If the number is present
number and check the number is present in the array or not using binary search.
then remnove the element from the array and rearrange the array.
Ouestion 8 [15]
array consists of 4 rows and
Write a program to input integersas elements in a two dimension find and display
4 columns. Find and display index of the row whose sum is maximum. Also
index of the column whose product is minimum.