You are on page 1of 1

Computer Achievers

MM-30 Time-1hr

Q1 Attempt All (Each question carry 1marks)

1. Identify and name the following tokens:


(i) public (ii) == (iii) { } (iv) ‘a’

2. Differentiate between if else if and switch case statements.

3. Give the output of the following code.


String P=”19″,Q=”20″;
int a=Integer.parseInt(P); int b=Integer.valueOf(Q); System.out.println(a+””+b);

4. Write a Java expression for the following: |x²+2xy|

5. Evaluate the following expression if the value of x=2, y=3 and z=1.
v=x+ –z+ y++ +y

6. What will be the output of the following code?


float x = 7.87;System.out.println(Math.ceil(x); System.out.println(Math.floor(x);

7. int i = 1; while(i++<=1) { i++; System.out.print(i + “ ” ); } System.out.print(i);

8. Rewrite the following using ternary operator:


if (bill >10000 ) discount = bill * 10.0/100; else discount = bill * 5.0/100;

9. Name the type of error (syntax, runtime or logical error) in each case given below:
(i) Math.sqrt (36-45)
(ii) int a;b;c;

10. Write a function prototype of the following: A function PosChar which takes a string argument and a character
argument and returns an integer value.

Q2 Write Java Programs and add suitable comments wherever necessary.


1. Write a menu driven program to find the sum of the following series depending on the user choosing 1 or 2
1. S=1/4+1/8+1/12.........upto n terms
2. S=1/1!-2/2!+3/3!.......upto n terms

2.Write a menu driven program to display the pattern as per user’s choice. For an incorrect option, an appropriate error
message should be displayed.
Pattern 1 Pattern 2
ABCDE B
ABCD LL
ABC UUU
AB EEEE
A

3. A computer salesman gets commission on the following basis:


Sales Commission Rate
Rs. 0 - 20,000 3%
Rs. 20,000 - 50,000 12%
Rs. 50,001 and more 31%
After accepting the sales as input, calculate and print his commission amount and rate of commission.

You might also like