Computer - IX
Computer - IX
Question 2 [10]
a) If a= 4, b = 3; find the value of c = a++ * 6 + ++b*5 +10;
b) What are the values of x and y when the following statements are executed?
int a = 63 , b = 36;
boolean x = (a>b)?a:b;
int y = (a<b)?a:b;
c) State the output of the program snippet given below
int a = 10 , b = 12;
if(a>=10)
a++ ;
else
++b ;
System.out.println(“a = “+a + “and b = “ +b);
d) Differentiate between next() and nextLine() functions.
e) Rewrite the following using ternary operator.
if(p>5000)
d = p*5/100;
else
d = p*2/100;
Question 3 [10]
Question 4 [10]
What values will be stored in the variables p and q after executing
a) double a= -99.51 , b = -56. 25;
double p =Math.abs(Math.floor(a));
double q = Math.sqrt(Math.abs(b));
b) double x= 5.9 , y= 6.5;
double p =(Math.min(Math.floor(x),y));
double q = (Math.max(Math.ceil(x),y));
c) int p =Math.abs(Math.min(-61 , -79));
double q = Math.cbrt(4.913);
d) int p = (Math.ceil(3.4) + Math.pow(2,3));
double q = (Math.floor(-4.7));
e) int p = Math.round(Math.pow(2.4, 2));
int q = Math.abs(Math.max(-8,-11));
Section B
Attempt Any Four
[60 Marks]
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 to take the input from user and
Variable descriptions/Mnemonic Codes so that the logic of the program is clearly depicted. Flowcharts and
Algorithms are not required.
Question 5 [15]
A company announces revised Dearness Allowance (DA) and Special Allowances (SA) for their employees
as per the tariff given below:
Dearness Special
Basic
Allowance(DA) Allowance (SA)
Up to Rs 10,000 10% 5%
Rs 10,001 – Rs 20,000 12% 8%
Rs 20,001 – Rs 30,000 15% 10%
Rs 30,001 and above 20% 12%
Write a program to accept the name and Basic Salary (BS) of an employee.
Calculate and display gross salary.
Gross Salary = Basic +Dearness Allowance +Special Allowance
Display the information in the given format :
Name Basic DA Spl.Allowance Gross
Salary
xxxxx xxxxx xxxxx xxxxxx xxxxxxx
Question 6 [15]
A special two-digit number is such that when the sum of its digits is added to the product of its digits, the
result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of its digits = 5 x 9 = 45
Sum of the sum of digits and product of digits= 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the
value is equal to the number input, output the message “Special 2-digit number” otherwise, output the
message “Not a Special 2-digit number”.
Question 7 [15]
Using a switch statement, write a menu driven program to convert a given temperature from Fahrenheit to
Celsius and vice versa. For an incorrect choice, an appropriate error message should be displayed.
5
C = 9 × (F – 32) and F = 1.8 × (C + 32)
Question 8 [15]
Write a menu driven program to print the following
1) 0,3,8,15……………………….upto n. Take the value of n from user.
2) To check and display whether a number input by user is a composite number or not.(A number is
said to be composite if it has one or more factors excluding one and number itself)
Question 9 [15]
Write a program in Java to find the sum of the given series:
S = 1+ (1*2) + (1*2*3) + ………………………+(1*2*3 *……….*n)
Take the value of n as input.
Question 10 [15]
A prime number is said to be ‘Twisted Prime’ , if the new number obtained after reversing the digits is also
a prime number. Write a program to accept a number and check whether the number is ‘Twisted Prime ‘ or
not.
Sample Input: 167
Sample Output: 761
167 is Twisted Prime
-------------xxxxxxx-------------