Method Related Progs

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

Global IQ Computer Education Centre

60,A.m.Bose Road Kolkata-74


1.Write a program in Java to find the sum of the series using function name product
(int,int) to return the product of two numbers in order to obtain each term.
S=(1*2)+(2*3)+(3*4)+…………………(9*10)
2.Wap in java to find the sum of the series using function name fact(int a)which returns
the factorial of the number a
s=1+1/2!+1/3!+………………………1/n!
3. Wap in java to find the sum of the series using function name fact(int m)which returns
the factorial of the number m
s=1+a2/2!+a3/3!+a4/4!............................an/n!
4.Wap in java to accept a number and check whether the number is prime or not using the
function name prchk(int n). The functions returns 1 if the number is prime otherwise 0.
5.Wap in java to accept two numbers and find the hcf and lcm of two numbers using
function name hlcm(int,int)
6.Wap in java to accept a number and check whether the number is palindrome or not
using function name reverse (int n) which returns the number after reversing the digits.
7.Using a function auto(int a) check a number is automorphic or not.
8.Wap to accept two numbers and check it’s twin prime or not using tprime(int m,int n).
9.Wap in java to calculate monthly electric bill of a consumer according to the units
consumed. The tariff is given below:
Units Consumed Charge
Up to 100 Units 90 paise per unit
For next 100 Units Rs 1 per unit
For next 200 Units Rs.1.25 per unit

Every consumer has to pay Rs.50 as service charge. Use a function charge (int u)
To find and print the electric charge.
10.Write a java program to interchange the value of the two numbers a and b and display
the result after swapping. Use overloaded methods display(int,int) and display(float,float)
for swapping integer and float values.
11.Wwp in java to input 10 numbers . Use a function to find and print cube of each
number.
12.Wap to input three sides of a triangle. Pass into a function triangle(int x,int y,int z) and
checks the triangle is equilateral, isosceles, scalene.
13.Wap in java to input day number. Use a function days(int d) to accept the day number
from the main class. The function uses a switch case statement to print the corresponding
days of week.
14.Write a java program to input a number. Use a function ams(int n) to receive the
number. The function returns 1 if the number is Armstrong otherwise 0.
15.Write a program using a function called area( ) to compute the area of
circle,square,rectangle. Using a menu driven approach.
16.Write the class with the name volume using function overloading that computes the
volume of a cube,sphere,cuboid.
Formula: Volume of a cube:s*s*s
Volume of a sphere:4/3*pie*r*r*r
Volume of a cuboid:l*b*h

Kallol Bhattacharya
Global IQ Computer Education Centre
60,A.m.Bose Road Kolkata-74
18.Write a class with the name perimeter using function overloading that computes the
perimeter of a square , rectangle and circle.

19.Write a class with the name Area using function overloading that computes the area of
a parallelogram, a rhombus and a trapezium.
Area of a parallelogram=b*h
Area of a rhombus=1/2*d1*d2(d1 and d2 are diagonals)
Area of a trapezium=1/2*(a+b)*h(a,b are parallel sides and h=perpendicular distance
between parallel sides)

20.Wap in java to accept the name of employee and his monthly income. Pass the name
and the annual income to a function tax(String name, int income) which displays the
name of the employee and the income tax as per as the given tariff.
Annual Income Income Tax
Up to 50000 No tax
Rs 50001 to Rs 100000 10% of income exceeding Rs.50000
Rs 100001 to Rs 150000 Rs 1000+20% of income exceeding 100000
Rs 150001 and above Rs 19000+30% of income exceeding
150000

21.Make a calculator using function arguments.

Kallol Bhattacharya

You might also like