0% found this document useful (0 votes)
4 views

Answer Script DBPS

The document contains answers to a programming-related questionnaire, covering topics such as byte code, variable types, error types, operator precedence, and Java programming constructs. It includes code examples for calculating electric bills, volumes of geometric shapes, and various number classifications. Additionally, it discusses comments in Java and the use of functions for multiple purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Answer Script DBPS

The document contains answers to a programming-related questionnaire, covering topics such as byte code, variable types, error types, operator precedence, and Java programming constructs. It includes code examples for calculating electric bills, volumes of geometric shapes, and various number classifications. Additionally, it discusses comments in Java and the use of functions for multiple purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Answer to Section A:

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

i) Floating point variable can be used with


this statement. i) Floating point variable can’t be used as a
ii) Can check any type of condition using <, switch variable
>, != etc. ii) Can check only equality condition
iii) Can use Logical operators.
iii) Can’t use any logical operator

5) double T=(s<=20) ? 1.35 : 0;

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

3) class long (Long1)


{ public static void Display(string args{}) (String args[] )
{
Int a=5;b=0;c=7; ( int a=5, b=0, c=7; )
if ++a > ++b ( if ( ++a > ++b ) )
{ if(a%b==0); ( if(a%b==0) )
c +=2 ( c+=2;)
}
System.out.print(a,c); ( System.out.print(a+” “ +c); )
}
}
4) nextDouble()
5) a>b is false then b > c is true because b=’c’ and c=’P’ so, ‘c’ > ‘P’ value of b will assign in int x. Since value of b is ‘c’ its
ASCII value is 99 the output will be X = 99.

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.

3) java.lang, other packages are java.io, java.util, java.awt

4) Single line comment starts with // to write one line remarks


Multi line comment starts with /* and ends with */ to write more than one line remarks
Documenting comment starts with /** and ends with */ to write more than one line remarks
6) import and new

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

4. when ch=’a’ , default will execute


++a = 4, ++b = 7, b=9*4=36 so output will be 4 36 9

when ch=’D’ , case ‘D’ and case ‘F’ will execute


a=7%8=7, a++ = 8
b=8*9=72 so output will be 8 72 9

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”);
}
}
}

You might also like