You are on page 1of 32

1.

Design a class to overload a function volume( ) as follows:


i. double volume(double r) — with radius (r) as an argument, returns the volume of
sphere using the formula:
V = (4/3) * (22/7) * r * r * r
ii.double volume(double h, double r) — with height(h) and radius(r) as the arguments,
returns the volume of a cylinder using the formula:
V = (22/7) * r * r * h
iii. double volume(double 1, double b, double h) — with length(l), breadth(b) and
height(h)
as the arguments, returns the volume of a cuboid using the formula:
V = l*b*h ⇒ (length * breadth * height)

CODE:
public class q1
{
double volume(double r) {
double vol = (4 / 3.0) * (22 / 7.0) * r * r * r;
return vol;
}

double volume(double h, double r) {


double vol = (22 / 7.0) * r * r * h;
return vol;
}

double volume(double l, double b, double h) {


double vol = l * b * h;
return vol;
}

public static void main(String args[]) {


Q1 obj = new q1();
System.out.println("Sphere Volume = " +
obj.volume(6));
System.out.println("Cylinder Volume = " +
obj.volume(5, 3.5));
System.out.println("Cuboid Volume = " +
obj.volume(7.5, 3.5, 2));
}
}
OUTPUT:

VDT:-

VARIABLE DATATYPE FUNCTION


vol double Store a function

l double Store a value

b double Store a value

h double Store a value

r double Store a value

ALGORITHM:
1. Start
2. Initialize class
3. Overloading function ‘volume’
4. Finding volume of different shapes in the function
5. Initializing main method
6. Calling each function and entering values
7. Showing required answer
8. Stop

2. Write a program to accept name and total marks of N number of students in two
single subscript array name[] and totalmarks[ ].
Calculate and print:
(i) The average of the total marks obtained by N Number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
CODE:
import java.util.Scanner;

public class q2
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = in.nextInt();9

String name[] = new String[n];


int totalmarks[] = new int[n];
int grandTotal = 0;

for (int i = 0; i < n; i++) {


in.nextLine();
System.out.print("Enter name of student " + (i+1) + ": ");
name[i] = in.nextLine();
System.out.print("Enter total marks of student " + (i+1) +
": ");
totalmarks[i] = in.nextInt();
grandTotal += totalmarks[i];
}

double avg = grandTotal / (double)n;


System.out.println("Average = " + avg);

for (int i = 0; i < n; i++) {


System.out.println("Deviation for " + name[i] + " = "
+ (totalmarks[i] - avg));
}
}
}

VDT:

VARIABLE DATATYPE FUNCTION


totalmarks int Store a value

n int Store a value

name String Store a value

avg double Store a function

grandTotal int Store a value


ALGORITHM:
1. Start
2. Input n as size of array

3. Declare name[n], totalmarks[n] and grandtotal[n]


4. sum<-0
5. i<-0

6. If i<n then goto line 6 otherwise line 10

7. Input “name :”,name[i]


8. Input “Total marks

3. Write a function fact(int n) to find the factorial of a number


n.Include a main class to
find the value of S where:
S = n! / (m!(n - m)!), where, n! = 1 x 2 x 3 x .......... x n

CODE:
import java.util.Scanner;
public class q3
{
public long fact(int n) {
long f = 1;
for (int i = 1; i <= n; i++) {
f *= i;
}
return f;
}
public static void main(String args[]) {
q3 obj = new q3();
Scanner in = new Scanner(System.in);
System.out.print("Enter m: ");
int m = in.nextInt();
System.out.print("Enter n: ");
int n = in.nextInt();
double s = (double)(obj.fact(n)) / (obj.fact(m) * obj.fact(n - m));
System.out.println("S=" + s);
}
}

OUTPUT:-

VDT:
VARIABLE DATATYPE FUNCTION
m int Store a value

n int Store a value

i int Control the loop

f long Store a function

ALGORITHM:
1. Start
2. Define function fact ( n)
3. f <- 1,i<-1
4. If i<=n then goto line 5 otherwise line
5. f*=i
6. i<-i+1 goto line 4
7. Return f
8. End function fact()
9. Accept m
10. Accept n
11. s<-fact(n)/(fact(m)*fact(n-m))
12. Display s
13. Stop

4. Write a program to input integer elements into an array of size 20


and perform the
following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array.

CODE:
import java.util.Scanner;
public class q4
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers:");
for (int i = 0; i < 20; i++) {
arr[i] = in.nextInt();
}
int min = arr[0], max = arr[0], sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < min)
min = arr[i];

if (arr[i] > max)


max = arr[i];

sum += arr[i];
}

System.out.println("Largest Number = " + max);


System.out.println("Smallest Number = " + min);
System.out.println("Sum = " + sum);
}
}

VDT:

VARIABLE DATATYPE FUNCTION


arr[] int Store a value

i int Controls loop

sum int Store a function

max int Store a value

min int Store a value


ALGORITHM:
1. Start
2. arr[20]
3. sum<-0
4. i<-0
5. If i<20 then goto line 6 otherwise line
6. Accept arrr[i]
7. sum<-sum+arr[i]
8. i<-i+1
9. max<-arr[0]
10. min<-arr[0]
11. i<-0
12. If i<20 then goto line 13 otherwise goto
13. If arr[i]>max then max=arr[i] goto 15 otherwise goto 14
14. If arr[i]<max then min=arr[i]
15. i<-i+1 goto line 12
16. Display sum
17. Display max
18. Display min
19. Stop

5. Write a program to input and store roll numbers, names and marks in
3 subjects of n
number students in five single dimensional array and display the remark
based on
average marks as given below :
(The maximum marks in the subject are 100)

CODE:
import java.util.Scanner;
public class q5
{
public static void main(String args[]) {

Scanner in = new Scanner(System.in);


System.out.print("Enter number of students: ");
int n = in.nextInt();
int rollNo[] = new int[n];
String name[] = new String[n];
int s1[] = new int[n];
int s2[] = new int[n];
int s3[] = new int[n];
double avg[] = new double[n];
for (int i = 0; i < n; i++) {
System.out.println("Enter student " + (i+1) + " details:");
System.out.print("Roll No: ");
rollNo[i] = in.nextInt();
in.nextLine();
System.out.print("Name: ");
name[i] = in.nextLine();
System.out.print("Subject 1 Marks: ");
s1[i] = in.nextInt();
System.out.print("Subject 2 Marks: ");
s2[i] = in.nextInt();
System.out.print("Subject 3 Marks: ");
s3[i] = in.nextInt();
avg[i] = (s1[i] + s2[i] + s3[i]) / 3.0;
}
System.out.println("Roll No\tName\tRemark");
for (int i = 0; i < n; i++) {
String remark;
if (avg[i] < 40)
remark = "Poor";
else if (avg[i] < 60)
remark = "Pass";
else if (avg[i] < 75)
remark = "First Class";
else if (avg[i] < 85)
remark = "Distinction";
else
remark = "Excellent";
System.out.println(rollNo[i] + "\t"
+ name[i] + "\t"
+ remark);
}
}
}

OUTPUT:-
VDT:

VARIABLE DATATYPE FUNCTION


n int Store a value

rollNo int Store a value

name String Store a value

s1 int Store a value

s2 int Store a value

s3 int Store a value

avg double Store a function

i int Controls loop

remark String Store a value

ALGORITHM:
1. Start
2. Define n and enter the value of the no of students.
3. Declare rollNo[n],name[n],s1[n],s2[n],s3[n], avg[n].
4. i<-0
5. If i<n then goto line 5 otherwise line 9
6. Accept rollNo[i], name[i], s1[i], s2[i], s3[i]
7. avg[i]<-(s1[i]+s2[i]+s3[i])/3
8. i<-i+1. Go to 5
9. i<-0
10. If i<n go to line 11 otherwise line 16
11. If avg[i] <40 print rollno[i], name[i], “poor”
12. Else if avg[i]<60 print rollno[i], name[i], ,”pass”
13. Else if avg[i]<-75 print rollno[i], name[i], “First Class”
14. Else if avg[i]<85 print rollno[i], name[i], “Distinction”
15. Else print rollno[i], name[i], “excellent”
16. i<-i+1 goto 10
17. end

6. Write a program in Java to store 20 numbers (even and odd numbers)


in a Single
Dimensional Array (SDA). Calculate and display the sum of all even
numbers and all
odd numbers separately.

CODE:
import java.util.Scanner;
public class q6
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int arr[] = new int[20];
System.out.println("Enter 20 numbers");
for (int i = 0; i < arr.length; i++) {
arr[i] = in.nextInt();
}
int oddSum = 0, evenSum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0)
evenSum += arr[i];
else
oddSum += arr[i];
}
System.out.println("Sum of Odd numbers = " + oddSum);
System.out.println("Sum of Even numbers = " + evenSum);
}
}

OUTPUT:-
VDT:

VARIABLE DATATYPE FUNCTION


arr[] int Store a value

i int Controls loop

oddSum int Store a value

evenSum int Store a value

ALGORITHM:
1. Start
2. Define class
3. Define function main()
4. even<-0
5. odd<-0
6. Display enter 20 no.s
7. i<-0
8. a[i] <-accept no.
9. i<-i+1.
10. Repeat steps 8 to 9 till i <20
11. i<-0
12. if(a[i] mod 2==0)
13. even<-even+a[i]
14. else
15. odd<-odd+a[i]
16. i<-i+1
17. repeat steps 12 to 16 till i<20
18. end if
19. display even
20. display odd
21. End main
22. End class
23. Stop

7. Write a program by using a class with the following specifications:


Class name — Hcflcm
Data members/instance variables:
int a
int b
Member functions:
Hcflcm(int x, int y) — constructor to initialize a=x and b=y.
void calculate( ) — to find and print hcf and lcm of both the numbers.

CODE:
import java.util.Scanner;
public class Hcflcm
{
int a , b ;
public Hcflcm(int x, int y) {
a = x;
b = y;
}
public void calculate() {
int x = a, y = b;
while (y != 0) {
int t = y;
y = x % y;
x = t;
}
int hcf = x;
int lcm = (a * b) / hcf;
System.out.println("HCF = " + hcf);
System.out.println("LCM = " + lcm);
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int x = in.nextInt();
System.out.print("Enter second number: ");
int y = in.nextInt();
Hcflcm obj = new q7(x,y);
obj.calculate();
}
}

OUTPUT:-

VDT:

VARIABLE DATATYPE FUNCTION


a int Store a value

b int Store a value

x int Store a value

y int Store a function

hcm int Store a value

lcm int Store a function

ALGORITHM:
1. Start
2. Define class Hcflcm
3. Declare int a and b
4. Create constructor Hcflcm(int x , int y)
5. a<-x , b<-y.
6. End constructor Hcflm.
7. Define function calculate()
8. x<-a , y<-b
9. If y<>0 then go to 10 otherwise goto 13
10. t<-y
11. y<-x%y
12. x<-t goto 9
13. Display x as “HCF”
14. Display (a*b)/x as “LCM”
15. End function calculate()
16. Define main
17. Declare x1,y1
18. Input x1,y1
19. Send values to constructor Hcflcm.
20. Call function calculate()
21. Stop

8. Write a program by using a class with the following specifications:


Class name — Calculate
Instance variables:
int num
int f
int rev
Member Methods:
Calculate(int n) — to initialize num with n, f and rev with 0 (zero)
int prime() — to return 1, if number is prime
int reverse() — to return reverse of the number
void display() — to check and print whether the number is a prime
palindrome
or not.

CODE:
import java.util.Scanner;
public class Calculate
{
private int num;
private int f;
private int rev;
public Calculate(int n) {
num = n;
f = 0;
rev = 0;
}
public int prime() {
f = 1;
if (num == 0 || num == 1)
f = 0;
else
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
f = 0;
break;
}
}
return f;
}
public int reverse() {
int t = num;
while (t != 0) {
int digit = t % 10;
rev = rev * 10 + digit;
t /= 10;
}
return rev;
}
public void display() {
if (f == 1 && rev == num)
System.out.println(num + " is prime palindrome");
else
System.out.println(num + " is not prime palindrome");
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int x = in.nextInt();
Calculate obj = new Calculate(x);
obj.prime();
obj.reverse();
obj.display(); }
}
OUTPUT:-
VDT:

VARIABLE DATATYPE FUNCTION


n int Store a value

num int Store a value

f int Store a value

rev int Store a function

i int Control Loop

t int Store a value

digit int Store a function

x int Store a value

ALGORITHM:
1. Start
2. Import scanner
3. Declare class Calculate
4. Define int num,f,rev
5. New constructor Calculate(int n)
6. declare these h=n,f=0,rev=0
7. End Calculate()
8. New function prime()
9. Calculate and return 1 if number is prime
10. End function prime().
11. New function reverse()
12. Find the reverse of num.
13. End function reverse()
14. New function display()
15. if f=1 and rev =num then print ‘prime palindrome else print ‘not prime
palindrome’.
16. End function display()
17. New main
18. Scanner in
19. Declare x ––
20. Input x
21. Send x to Calculate()
22. Call other functions.
23. End

9. An electronics shop has announced a special discount on the purchase


of Laptops as
given below:
Category Discount on Laptop
Up to ₹25,000 5.0%
₹25,001 - ₹50,000 7.5%
₹50,001 - ₹1,00,000 10.0%
More than ₹1,00,000 15.0%
Define a class Laptop described as follows:
Data members/instance variables:
1. name
2. price
3. discount
4. amt
Member Methods:
1. A parameterised constructor to initialize the data members
2. To accept the details (name of the customer and the price)
3. To compute the discount
4. To display the name, discount and amount to be paid after discount.
Write a main method to create an object of the class and call the
member methods.
CODE:
import java.util.Scanner;
public class Laptop
{
String name;
int price;
double dis;
double amt;
public Laptop(String s, int p)
{
name = s;
price = p;
}
public void compute() {
if (price <= 25000)
dis = price * 0.05;
else if (price <= 50000)
dis = price * 0.075;
else if (price <= 100000)
dis = price * 0.1;
else
dis = price * 0.15;
amt = price - dis;
}
public void display() {
System.out.println("Name: " + name);
System.out.println("Discount: " + dis);
System.out.println("Amount to be paid: " + amt);
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Customer Name: ");
String str = in.nextLine();
System.out.print("Enter Price: ");
int p = in.nextInt();
Laptop obj = new Laptop(str,p);
obj.compute();
obj.display();
}
}

OUTPUT:-
VDT:

VARIABLE DATATYPE FUNCTION


name String Store a value

price int Store a value

dis double Store a function

amt double Store a function

s String Store a value

p int Store a value

str String Store a value

ALGORITHM:
1. Start
2. Import scanner
3. Declare class
4. Define String name , double price , amt , dis.
5. New constructor Laptop(String name , double p)
6. declare these name = n; price = p; dis=0.0; amt=0.0;
7. End Laptop()
8. New function Compute()
9. Calculate the discount and the amount
10. End function Compute().
11. New function Display()
12. To print the values
13. End functionDisplay()
14. New main
15. Scanner in
16. Take the inputs
17. Send n1,p1 to Laptop()
18. Call other functions.
19. End

10. 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”.

CODE:
import java.util.Scanner;
public class q10
{
public void checkNumber() {
Scanner in = new Scanner(System.in);
System.out.print("Enter a 2 digit number: ");
int orgNum = in.nextInt();
int num = orgNum;
int count = 0, digitSum = 0, digitProduct = 1;
while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++; }
if (count != 2)
System.out.println("Invalid input, please enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit number");
}
}

OUTPUT:-

VDT:

VARIABLE DATATYPE FUNCTION


orgNum int Store a value

num int Store a function

count int Store a value

digitSum int Store a function

digitProduct int Store a function

digit int Store a function

ALGORITHM:
1. Start Initialize class

2. Take number(2-digit)

3. Summing each digit

4. Multiplying each digit

5. Counting length

6. Checking for special number

11. Design a class to overload a function area( ) as follows:


(i) double area (double a, double b, double c) with three double
arguments, returns
the area of a scalene triangle using the formula:
area = √s(s − a)(s − b)(s − c) where s=(a+b+c)/2
(ii) double area (int a, int b, int height) with three integer
arguments, returns the
area of a trapezium using the formula:
area = 1/2 height (a + b)
(iii) double area (double diagonal 1, double diagonal 2) with two
double arguments,
returns the area of a rhombus using the formula :
area = 1/2 (diagonal 1 x diagonal 2)

CODE:
import java.util.Scanner;
public class q11
{
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
double x = s * (s-a) * (s-b) * (s-c);
double result = Math.sqrt(x);
return result;
}
double area (double a, double b, double height) {
double result = (1.0 / 2.0) * height * (a + b);
return result;
}
double area (double diagonal1, double diagonal2) {
double result = 1.0 / 2.0 * diagonal1 * diagonal2;
return result;}
}

OUTPUT:-
VDT:

VARIABLE DATATYPE FUNCTION


a double Store a function

b double Store a function

c double Store a function

s double Store a function

x double Store a function

result double Store a function

height double Store a function

diagonal1 double Store a function

diagonal2 double Store a function

ALGORITHM:
1. Start

2. Overloading function names ‘area’

3. Calculating areas of various shapes in ‘area’ function

4. Returning result in each case

5. Stop

12. Using the switch statement, write a menu driven program to calculate the
maturity amount of a Bank Deposit.
The user is given the following options:
1. Term Deposit
2. Recurring Deposit
For option 1, accept principal (P), rate of interest(r) and time period in
years(n). Calculate and output the maturity amount(A) receivable using
the formula:
A = P[1 + r / 100]n
For option 2, accept Monthly Installment (P), rate of interest (r) and
time period in months (n). Calculate and output the maturity amount
(A) receivable using the formula:
A = P x n + P x (n(n+1) / 2) x r / 100 x 1 / 12
For an incorrect option, an appropriate error message should be
displayed.

CODE:
import java.util.Scanner;
public class q12
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Term Deposit");
System.out.println("Type 2 for Recurring Deposit");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
double p = 0.0, r = 0.0, a = 0.0;
int n = 0;
switch (ch) {
case 1:
System.out.print("Enter Principal: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in years: ");
n = in.nextInt();
a = p * Math.pow(1 + r / 100, n);
System.out.println("Maturity amount = " + a);
break;
case 2:
System.out.print("Enter Monthly Installment: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in months: ");
n = in.nextInt();
a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
System.out.println("Maturity amount = " + a);
break;
default:
System.out.println("Invalid choice");
}
}
}

OUTPUT

VDT:

VARIABLE DATATYPE FUNCTION


ch int Store a Value

p double Store a Value

r double Store a Value

a double Store a Function

n int Store a Value

ALGORITHM:

1. START

2. INITIALIZE CLASS

3. MAIN METHOD
4. TAKING INPUT

5. CALCULATING AMOUNT IN EVERY CASE

6. CHECKING FOR ERROR CASE

7. RETURNING ANSWER

8. END

13. Write a program to accept the year of graduation from school as an integer value
from, the user. Using the Binary Search technique on the sorted array of integers
given below.
Output the message “Record exists” If the value input is located in the array. If not,
output the message “Record does not exist”.{1982, 1987, 1993, 1996. 1999, 2003,
2006, 2007, 2009, 2010}

CODE:
import java.util.Scanner;
public class q13
{
public static void main() {
Scanner sc = new Scanner(System.in);
int n[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};
System.out.print("Enter graduation year to search: ");
int year = sc.nextInt();
int l = 0, h = n.length - 1, idx = -1;
while (l <= h) {
int m = (l + h) / 2;
if (n[m] == year) {
idx = m;
break;
}
else if (n[m] < year) {
l = m + 1;
}
else {
h = m - 1;
}
}
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
OUTPUT:

VDT:

VARIABLE DATATYPE FUNCTION


n[] int Store a Value

year int Store a Value

l int Store a Value

h int Store a Function

idx int Store a Value

m int Store a Function

ALGORITHM:
1. Start
2. Define class
3. Define function main()
4. lb=0;
5. k=0
6. p=0
7. ub=0
8. i=0
9. display enter number in the cell.
10. m[i]sc.nextInt();
11. i=i+1.
12. Repeat steps 6 and 7 till i<10.
13. Display enter no. to be searched
14. nsaccept no.
15. p(lb+ub)/2
16. if(m[p]>ns)
17. ubp-1.
18. If(m[p]<ns)
19. lbp+1.
20. If(m[p]==ns)
21. K=1.
22. Break the program.
23. End if for line 18.
24. Repeat steps 15 to 21 till lb<=ub.
25. If(k==1)
26. Display record exists
27. Else
28. Display record does not exist
29. End if
30. End main
31. End class
32. Stop

14. Define a class named Fruit Juice with the following description:
Instance variables / data members :
int product_code — stores the product code number
String flavour — stores the flavour of the juice (E.g. orange, apple,
etc.)
String pack_type — stores the type of packaging (E.g. tetra-pack, PET
bottle, etc.)
int pack_size — stores package size (E.g. 200 ml, 400 ml, etc.)
int product_price — stores the price of the product

Member methods :
(i) FruitJuice() — Default constructor to initialize integer data
members to 0 and
String data members to “ ”.
(ii) void input( ) — To input and store the product code, flavour, pack
type, pack
size and product price.
(iii) void discount( ) — To reduce the product price by 10.
(iv) void display() — To display the product code, flavour, pack type,
pack size
and product price.

CODE:
import java.util.Scanner;
public class FruitJuice
{
int product_code;
String flavour;
String pack_type;
int pack_size;
int product_price;

public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Flavour: ");
flavour = in.nextLine();
System.out.print("Enter Pack Type: ");
pack_type = in.nextLine();
System.out.print("Enter Product Code: ");
product_code = in.nextInt();
System.out.print("Enter Pack Size: ");
pack_size = in.nextInt();
System.out.print("Enter Product Price: ");
product_price = in.nextInt();
}

public void discount() {


product_price -= 10;
}

public void display() {


System.out.println("Product Code: " + product_code);
System.out.println("Flavour: " + flavour);
System.out.println("Pack Type: " + pack_type);
System.out.println("Pack Size: " + pack_size);
System.out.println("Product Price: " + product_price);
}

public static void main(String args[]) {


FruitJuice obj = new FruitJuice();
obj.input();
obj.discount();
obj.display();
}
}

OUTPUT:

VDT:

VARIABLE DATATYPE FUNCTION


product_code int Store a value

flavour String Store a value

pack_type String Store a value

pack_size int Store a value

product_price int Store a function

ALGORITHM:
1. Start

2. Initialize class

3. Taking inputs

4. Making a constructor for input

5. Doing necessary calculations for a bill as provided in the question

6. Returning bill

7. Stop

15. A tech number has even number of digits. If the number is split in
two equal halves,
then the square of sum of these halves is equal to the number itself.
Write a program to
generate and print all four digits tech numbers.
Example
Consider the number : 3025
Square of sum of the halves of 3025=(30+25)2= (55)2
=3025 is a tech number.

CODE:
public class q15
{
public static void main(String args[]) {
for (int i = 1000; i <= 9999; i++) {
int secondHalf = i % 100;
int firstHalf = i / 100;
int sum = firstHalf + secondHalf;
if (i == sum * sum)
System.out.println(i);
}
}
}
OUTPUT:

VDT:

VARIABLE DATATYPE FUNCTION


i int Controls loop

secondHalf int Store a function

firstHalf int Store a function

sum int Store a function

ALGORITHM:

1. Start

2. Initialize class

3. Iterating 1000 to 9999

4. Dividing the number into two halves

5. Checking for tech number

6. Returning result

7. Stop

You might also like