Answer Script DBPS
Answer Script DBPS
1) Byte code is the machine readable code generated when we compile the source code, which is interpreted by
the Java Virtual machine. It is platform independent. Extension name is .class.
2) int-4 bytes, float-4 bytes
3) a.Run time error b.Syntax error.
4) if else Switch case
B)
1) u*t + ½.0*f*t*t; Math.pow(X, 3)+3*X*X+Math.sqrt(Math.pow(X,5)+7);
2) First condition 31 < 32(true)
j=32, k=33
Second condition 32%4==0 (true)
k=33+32=65
Output will be
J=32 K=65
C)
1) z= 5/3 * 9 – 2 * 5 % 9
z=1*9 – 10%9
z=9-1=8
2) It is the process of using a function for more than one purpose. It allows the use of different internal structure of the
object by keeping the same external interface.
D)
1) Operator precedence refers the order of evaluation of the operators in an expression. For example increment or
decrement operators evaluate before /, * or %.
2) switch(c )
{ case ‘A’ : case ‘a’ : System.out.println(“It is a letter”); break;
case ‘0’ : case ‘9’ : System.out.println(“It is a number”); break;
case ‘@’ : case ‘%’ : System.out.println(“It is a special character”); break;
default: System.out.println(“Garbage value”); }
3) Sum =
42
value is= 8
Answer to Section B:
1)
import java.util.*;
class Electric
{
public static void Display()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Enter name, consumer no and Units consumed”);
String n=sc.nextLine();
int con=sc.nextInt();
int u = sc.nextInt();
double bill=0.0, tbill=0.0;
if(u <= 100)
bill=u * 3.75;
else if (u<=250)
bill=100*3.75 + (u-100) * 4.25;
else if (u<=400)
bill=100*3.75 + 150 * 4.25 + (u-250)*5.85;
else
bill=100*3.75+150+4.25+150*5.85+(u-400)*7.25;
tbill = bill + bill * 12.5/100;
System.out.println(“Name : “+n);
System.out.println(“Consumer no : “+con);
System.out.println(“units consumed : “+u);
System.out.println(“Total Bill amount : “+tbill);
}
}
2)
import java.util.*;
class Menu
{
public static void Display()
{
Scanner sc = new Scanner(System.in);
System.out.println(“Press C for volume of cube”);
System.out.println(“Press B for volume of cuboid”);
System.out.println(“Press S for volume of sphere”);
System.out.println(“Enter choice”);
char ch = sc.next().charAt(0);
double vol=0.0;
switch(ch)
{
case ‘C’: case ‘c’:
System.out.println(“Enter side of cube”);
int s=sc.nextInt();
vol=Math.pow(s, 3);
System.out.println(“Volume of cube”+vol);
break;
case ‘B’: case ‘b’:
System.out.println(“Enter length, breadth and height”);
int L=sc.nextInt(); int B=sc.nextInt(); int H=sc.nextInt();
vol=L * B * H;
System.out.println(“Volume of cuboid”+vol);
break;
case ‘S’: case ‘s’:
System.out.println(“Enter radius of sphere”);
int R=sc.nextInt();
vol=4/3.0 * 3.14 * Math.pow(R, 3);
System.out.println(“Volume of sphere”+vol);
break;
default:
System.out.println(“Wrong choice”);
}
}
}
3.a)
class Digit
{
public static void Display(int n)
{
if( n>99 && n<1000)
{
int L=n%10;
int M=(n%100)/10;
int F=n/100;
int rev = L*100+M*10+F;
System.out.println(“Reverse is = ”+rev);
}
else
System.out.println(“Not a 3 digit number”);
}
}
3.b)
class BuzzNo
{
public static void Display(int n)
{
if( n%10 == 7 || n % 7 == 0 )
System.out.println(“Buzz No”);
else
System.out.println(“Not a Buzz No”);
}
}
4)
class Number
{
public static void Display(double n)
{
int x = (int)n + 1;
System.out.println(“Nearest higher value is = “ + x);
double y = Math.sqrt(x);
if ( y == (int) y)
System.out.println(x+” is Perfect square”);
else
System.out.println(x+” is not Perfect square”);
}
}
5)
class Triangle
{
public static void Display(int a, int b, int c)
{
if(a+b>c && a+c>b && b+c>a)
{
System.out.println(“Triangle is possible”);
if(a==b && b==c)
System.out.println(“Equilateral triangle”);
else if(a==b || b==c || c==a)
System.out.println(“Isosceles triangle”);
else
System.out.println(“Scalene triangle”);
}
else
System.out.println(“Triangle not possible”); } }
6)
class TechNo
{
public static void Display(int n)
{
if ( n<1000 || n>9999)
System.out.println(“Not a four digit number”);
else
{
int a = n/100 + n%100;
int b = a*a;
if(n == b)
System.out.println(n+” is a Tech no”);
else
System.out.println(n+” is not a Tech no”);
}
}
}