Page 319 - CA_Blue( J )_Class9
P. 319
Ans. int ch,a=7,b=2;
switch(ch)
{
case 1:
System.out.println("Sum " + (a+b));
break;
case 2:
System.out.println("Difference " +(a-b));
break;
default : System.out.println("Product " +(a*b));
}
(ix) Find the error and correct them: [2]
if(a==1)
System.out.println("A is one");
else if(b==2);
{
system.out.println("B is two");
else
System.out.println("C is three");
Ans. if(a==1)
System.out.println("A is one");
else if(b==2)
{
System.out.println("B is two");
}
else
System.out.println("C is three");
(x) What are the final values stored in variables x and y below? [2]
double a = -6.35;
double b = 14.74;
double x = Math.abs(a);
double y = Math.rint(b);
Ans. x = 6.35
y = 15.0
SECTION B
Attempt any four questions from this Section.
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 Variable descriptions/Mnemonic Codes such that the logic
of the program is clearly depicted.
Flowcharts and algorithms are not required
Question 3. [15]
Write a program to input the units of electricity consumed by a customer and print the bill amount to be paid according to the
following criteria.
Units of electricity Rate per unit
First 100 units 4.5 per unit
next 250 units 5.5 per unit
next 300 units 7 per unit
above 650 units 9 per unit
Ans. import java.util.*;
class electricity_consumed
{
public static void main()
{
Scanner sc=new Scanner(System.in);
Model Test Paper 317

