Section - A: I) Ii) Iii) C (X 'A' && X 'Z') ? "Upper Case Letter": "Lower Case Letter"

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SECTION – A

1. a) Name the different ways to manage the flow of control in a Java program.?
b) Differentiate between if and switch statement?
c) Explain 'Fall through' with reference to a switch case statement?
d) What is a compound statement? Give an example.
e) Differentiate between Math.rint( ) and Math.round( )?
f) Differentiate between break and continue?
g) What is meant by data type? Name two types of data type.
h) Explain the term type casting? How many types are they in Java ?
i) What is an operator? What are the three main types of operators? Name them.
j) Differentiate between System.out.print() and System.out.println().
2. a) Predict the output:
i) int a=1,b=1,m=10,n=5;
if((a==1)&&(b==0))
{
System.out.println((m+n));
System.out.println((m—n));
}
if((a==1)&&(b==1))
{
System.out.println((m*n));
System. out.println((m%n));
}
ii) int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
System.out.println(r);
}
else
{
c=a/b;
System.out.println(c);
}
iii) int k=5,j=9;
k+= k++ - ++j + k;
System.out.println("k="+k);
System.out.println("j="+j);
iv) a+= a++ + ++a + --a + a--; when a = 7;
v) when a. opn= ‘b’ b. opn= ‘x’ c. opn= ‘a’
switch(opn)
{
case ‘a’:
System.out.println(“Platform Independent”);break;
case ‘b’:
System.out.println(“Object Oriented”);
case ‘c’:
System.out.println(“Robust and Secure”); break;
default:
System.out.println(“Wrong Input”);
}
b) Rewrite the following program segment using if-else statements instead of the ternary operator.
i) String grade = (marks>=90)?"A": (marks>=80)? "B": "C";
ii) commission = (sale > 5000) ? sale*10/100 : 0;
iii) c = (x >= 'A' && x<= 'Z') ? "Upper Case Letter" : "Lower Case Letter";
c) Rewrite the following using ternary operator.

i) if(a > b)
{
if (a > c)
g = a;
else
g = c;
}
else if (b > c)
g = b;
else
g = c;

ii) double discount =0.0d;


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

SECTION –B (ANSWER ANY FOUR)

3. Write a program to input the Selling Price and Cost Price of a commodity and
find the percentage of Profit or Loss made upon selling the product.
4. Write a menu driven program that accept an integer and test as per user choice
Choice 1: +ve or –ve or ZERO
Choice 2: perfect squear or not
5. Write a program to accept a mark obtained by a student in computer science and
print the grades accordingly:
Marks Grade
Above 90 A
70 to 90 B
50 to 69 C
34 to 50 D
Below 34 F
6. An electricity company charges their consumers according to the units consumed
per month according to the given traffic:
Units Consumed Charges
Up to 100 units ₹ 2 per unit
More than 100 units and up to 200 units ₹ 1.80 per unit
More than 200 units ₹ 1.50 per unit
In addition to the above, every consumer has to pay ₹ 200 as Service Charge per
month. Write a program to input the amount of units consumed and calculate the
total charges payable (Bill) by the consumer.
7. Write a program to input an integer and check whether it is a 5-digit number or
not. If it is extract the central digit and print it.
Example
INPUT: Enter an integer: 76549
OUTPUT: Central digit: 5
8. Write a program to input a year and check whether it is a leap year or not
using ternary operator.

You might also like