[Go to site: main page, start]

0% found this document useful (0 votes)
6 views3 pages

Method Over Loading Lab

The document outlines various Java programming exercises, including static and non-static methods for addition, power calculation, area computation, prime number checking, palindrome checking, maximum number finding, and strong number verification. Each section includes a menu-driven approach for user interaction to select the desired operation. The exercises emphasize method overloading and user input handling.

Uploaded by

priyalipu37
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Method Over Loading Lab

The document outlines various Java programming exercises, including static and non-static methods for addition, power calculation, area computation, prime number checking, palindrome checking, maximum number finding, and strong number verification. Each section includes a menu-driven approach for user interaction to select the desired operation. The exercises emphasize method overloading and user input handling.

Uploaded by

priyalipu37
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Core java by Mahendra Sir

1. Addition Program (Static Methods)


Create a class and define static overloaded methods with name add:

●​ add(int a, int b) → return sum of two integers


●​ add(double a, double b) → return sum of two double values
●​ add(int a, double b) → return sum of one integer and one double

Menu Driven Program:

i
ah
Display the following menu:

●​ Enter 1 to find sum of two integer values


●​ Enter 2 to find sum of two double values
●​ Enter 3 to find sum of one integer and one double value

M
Take input from user and call respective method.
ith
2. Power Program (Static)
Define methods power:
eW

●​ power(int base, int exp)


●​ power(double base, int exp)

Menu:
od

●​ Enter 1 to calculate power of integer base


●​ Enter 2 to calculate power of double base
C

2. Area Calculation (Non-Static)


Define methods area:

●​ area(int side) → square


●​ area(int length, int breadth) → rectangle
●​ area(double radius) → circle

Menu:

“Time is precious, don’t waste it. Use wisely”Page 1


Core java by Mahendra Sir

●​ Enter 1 to find area of square


●​ Enter 2 to find area of rectangle
●​ Enter 3 to find area of circle

3. Prime Number Program (Static)


Define methods checkPrime:

i
●​ checkPrime(int n) → check single number

ah
●​ checkPrime(int start, int end) → print primes

Menu:

●​ Enter 1 to check whether a number is prime

M
●​ Enter 2 to print prime numbers in a given range
ith
4. Palindrome Number Program (Non-Static)
Define methods checkPalindrome:
eW

●​ checkPalindrome(int n)
●​ checkPalindrome(int start, int end)

Menu:

●​ Enter 1 to check whether a number is palindrome


od

●​ Enter 2 to print palindrome numbers in a range

5. Maximum Number Program (Static)


C

Define methods max:

●​ max(int a, int b)
●​ max(int a, int b, int c)
●​ max(double a, double b)

Menu:

“Time is precious, don’t waste it. Use wisely”Page 2


Core java by Mahendra Sir

●​ Enter 1 to find maximum of two integers


●​ Enter 2 to find maximum of three integers
●​ Enter 3 to find maximum of two double values

6. Strong Number Program (Non-Static)


Define methods checkStrong:

i
ah
●​ checkStrong(int n)
●​ checkStrong(int start, int end)

Menu:

M
●​ Enter 1 to check whether a number is a strong number
●​ithEnter 2 to print strong numbers in a given range
eW
od
C

“Time is precious, don’t waste it. Use wisely”Page 3

You might also like