Professional Documents
Culture Documents
Maximum Marks: 50
Time allowed: One hour (inclusive of reading time)
ALL QUESTIONS ARE COMPULSORY.
The marks intended for questions are given in brackets [ ]
a2 +b2 x (a+b) 5
axb
1. 4 2. 5 3. 1 4. 3
Question 2 [5x1=5]
Fill in the blanks with the correct option.
d. != is a ___________ operator.
1. Logical 2.Relational
2.Assignment 4.Arithmetic
Question 3 [5x1=5]
Name the following :
b.Scanner class has to be imported to accept values using the next() function.
1.true 2.false
c.The function Integer.parseInt() is used to convert an int value into a String value.
1.true 2.false
Question 5 [5x1=5]
Choose the odd one
Question 6 [5x1=5]
1.Give the output of the following :
b int a=6,b=3,c=9;
int x=(a--)-(--a)+(b++)*(--c);
1.23 2. 22 3. 26 4. - 26
c. Math.pow(Math.max(5,3), Math.min(5,3));
d. class A
{
static int add(int a)
{
return a+10;
}
static double add(double a)
{
return a+20;
}
void calc()
{
int x=add(50);
System.out.println(“The value of x is :”+x);
}
}
e. int n = 2;
switch (n)
{
case 1: System.out.println(“One”);
case 2: System.out.println(“Two”);
case 3: System.out.println(“Three”);
case 4: System.out.println(“Four”);
break;
default: System.out.println(“Invalid number”);
}
1. One
Two
Three
Four
2. Two
Three
Four
3. Two
Three
4. Two
Three
Four
Invalid number
Question 7
A company announces revised Dearness Allowance (DA) and Special Allowance (SA) for their
employees as per the tariff given below :
Basic DA SA
Upto Rs.10,000 10% 5%
Rs.10,001 to Rs.20,000 12% 8%
Rs.20,001 to Rs.30,000 15% 10%
Rs.30,001 and above 20% 12%
WAP to accept the name and Basic Salary of an employee and calculate and display the
gross salary.
Gross Salary = Basic + Dearness Allowance + Special Allowance
Display the information in the given format :
Name Basic DA Spl. Allowance Gross Salary [6x1=6]
….. ….. ….. ….. ……
import java.util.Scanner;
class EmployeeSalary
{
public static void main(String args[])
{
String name;
double basic, da, sa, gross, daPerc, saPerc;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the employee name :");
name=sc.nextLine();
System.out.println("Enter the basic salary :");
(a) __________
if(basic<=10000)
{
(b)___________
saPerc=5.0;
}
else if((c)___________)
{
daPerc=12.0;
saPerc=8.0;
}
else if(basic>=20001 && basic<=30000)
{
daPerc=15.0;
saPerc=10.0;
}
else
{
daPerc=20.0;
(d)_____________
}
da=(daPerc/100)*basic;
(e)_______________
System.out.println("Name\t\tBasic\tDA\tSpl. Allowance\tGross Salary");
(f)_______________
}
}
(a)1. basic=sc.nextInt();
2. basic=sc.nextDouble();
3. basic=sc.next();
(b)1. daPerc=10.0;
2. daPerc=5.0;
3. daPerc=10.0/10;
(d) 1. saPerc=12.0;
2. saPerc=12.0/10;
3. saPerc=20.0;
(e)1.sa=(saPerc/10.0) * basic;
2.sa=saPerc * basic;
3. sa=(saPerc/100)*basic;
Question 8
WAP to create a class Overload, with the specifications given below :
display() – 1/2 + 2/3 + 3/4 + ………..+ 19/20
display(int a, int n) – S= 1/a + 1/ a2 + 1/ a3+……..+1/an
main()-calls the above method and passes the values of a and n. [6x1=6]
class Overload
{
static void display()
{
double sum=0.0;
double n, d;
for(n=1.0, (a)_______;n<=19.0; n++, d++)
{
sum=(b)__________
}
System.out.println("The sum of the series is :"+sum);
}
static void display((c)__________)
{
double sum=0.0;
for(int i=1; (d)________; i++)
{
sum+=(e)____________
}
System.out.println("The sum of the series is :"sum);
}
public static void main(String args[])
{
(f)__________
display(3,10);
}
}
(a)1. d=1.0
2. n=2.0
3. d=2.0
(b)1. sum+(n/d);
2. sum=sum+n/d;
3. sum+ (n*d);
(c)1.int a, double n
2.int a; int n;
3. int a, int n
(d)1. i<=n
2. i<n ;
3. i<=10
(e) 1. Math.pow(a,i);
2. 1/Math.pow(a ,i);
3. 1/Math.pow(a,a);
(f)1. display(10 );
2. display();
3. ob.display();
Question 9
The following program segment displays the sum of the digits of a number n. (A perfect
square is a number the square root of which is an integer number.)
Complete it by choosing the appropriate options. [4x1=4]
void perfectSquare(int n)
{
(a)__________ sq, flr;
sq=(b)____________
flr=Math.floor(sq);
if((c)______________)
(d)____________________
else
System.out.println(“The number “+n+” is not a Perfect square”);
}
(a)1. double
2. int
3. float
(b)1. sqrt(n);
2. Math.sqrt(n);
3. Math.ceil(n);
(c)1. sq != flr
2. sq==flr
3. flr==n
Question 10
Read the paragraph given below and answer the questions given below.
Case study 1
The flow of control during the execution of a program takes place in the following ways :
i)Normal / Sequential flow of control
ii)Conditional flow of control
iii)Multiple branching of control
In the Normal flow of control, the statements are executed one after the other in a
sequence.
In a Conditional flow of control, a condition is checked and if the condition evaluates to
true, one set of statements are executed, otherwise another set of statements are
executed. The constructs if, if-else, if-else if, nested if, ternary operator are Conditional
statements.
In Multiple branching of control, a particular block of statements are executed out of a
number of blocks, as per the user’s choice. Switch-case is a multiple branching
construct. In this based on the value of a variable, the block of statements pertaining to
the matching case value is executed. A break statement is used to terminate a block.
[4x1=4]
(a)A set of statements are executed based on a condition check.
1. Normal flow
2. Conditional flow
3. Multiple-branching
xxxxxxxxxxx