You are on page 1of 4

1. A.

Which of the following is not a valid literal (1)


5 a ‘a’ “a”

b. Which of the following is not a keyword (1)


void, for, class, object

c. Math.ceil(-6.7) (1)

d. Which of the following datatype cannot be used in switch case


int, char, String, double (1)

e. Which of the following is not a relational operator (1)


= >= == !=

f. Which of the following is not an OOP principle (1)


Abstraction Polymorphism Identifier Inheritance

g. Which of the following is not a valid datatype


integer short long double (1)

h. find x if x = ++a + a-- + a++ if a = 5 (2)


I.What code is generated when java program is compiled (1)
Machine code, source code, byte code, object code

2. A. Convert into switch case (2)


void work(char code)
{
if(code == ‘A’)
System.out.println(“Accountant”);
else if (code == ‘C’ || code==’G’)
System.out.println(“Grade iv”);
else
System.out.println(“Financial Advisor”);
}

b. Write an expression that uses a conditional operator to set the value of discount to
10 if price is less than 1500 and to 15 otherwise (2)
c. Decalre a variable PI, and assign the fixed value 3.142 to it. (2)
d. Write and explain the 2 different styles of expressing a comment in a program (2)
e. find 15 – 30/4 + 9*6 %5 (2)

3. A. Name the following: (6)


 Character set used in java
 Represent non graphic characters
 Operators that act on one operand
 Reserved words in java
 Smallest individual unit in java
 An instance of a class
b. int i = 10, j = 10, a=100, b=50; (2)
if(a < 100)
{ if(b > 50)
++i;
}
else
++j;
System.out.print(“i=”+ i + “\n” + “j=”+ j);
c. int a = 10, b=15; (2)
a = a+b;
b = a-b;
a = a-b;
System.out.println(“a=”+a + “\t” + “b=”+ b);
d. Complete the following:
Scanner sc = ______ Scanner(___________); (2)
e. What is an infinite loop ? Write an infinite loop statement (2)
f. find the error and rewrite the correct code (2)
Switch(n)
{
case 1: a=11; b = 22; break;
Case 2: c=33; break; d=44;
}
g. int a = 20, b = 100;
if((a < b) && (b++ < 25))
System.out.println(b); (2)
h. Write java expression for f = uv (2)
u+v

DO all the 6 programs. Will give marks for the best 4


4. A set of 2 linear equations with 2 unknown values x1 and x2 are given as:
m = ax1 + bx2    and n = cx1 + dx2
The solution of the equation is given as
x1 = md - bn    and  x2 = na - mc
        ad - cb                      ad - cb
provided  the denominator is not equal to 0. If it is , print an appropriate message.
WAP that will accept the values of a,b,c,d,m and n and compute and display the
results of x1 and x2. (15)

5. Write a menu driven program to generate the sum of the given series
-- s = 1/1 + 1/2 + 1/3 + …. + 1/n
-- s = 1/a2 + 4/a5 + 7/a8 +….. to n terms (15)
6. A prepaid taxi charges from the passengers as per the tariff given below:
Distance rate
Upto 5 km Rs. 60
For next 10 km Rs 10/km
For next 10 km Rs 8/km (15)
More than 25 km Rs 5/km
WAP to input the distance covered and calculate the amount paid by the passenger.

7.1. WAP to enter a number and check whether the number is a “Neon” number or
not. A number is said to be Neon , if sum of the digits of square of a number is equal
to the number itself. E.g. 9
9*9 = 81 8+1 =9 So 9 is a Neon number (8)

7.2. WAP to calculate the sum of following series


S = 1+1+2+3+5+8+…. n terms (7)

8. WAP to accept the number of days and convert days into years, months and days.
Display total number of years, months and days present. Ignore leap years.
Assume 1 year = 365 days and 1 month = 30 days
e.g. days = 400
output = 1 year 1 month and 5 days (15)
9. WAP to accept the marks obtained and print the grade based on the marks obtained
according to the following table: (15)
Marks Grade
More than 85 A
More than equal to 70 ad upto 85 B
More than equal to 50 and upto 69 C
More than equal to 40 and upto 49 D
Less than 40 F

Answers
A
Object
-6.0
Double
=
17
bytecode
12
I=10
J=11
A=15 b=10
No output

You might also like