0% found this document useful (0 votes)
3 views1 page

Java Method Overloading Example

The document contains a Java class named 'Overload' that demonstrates method overloading with three different 'series' methods. The first method calculates the sum of factorials from 1 to 7, the second computes the sum of the reciprocals of numbers from 2 to a given value x, and the third prints a pattern based on two input integers m and n. The main method creates an instance of the class, calls these methods, and interacts with the user for input.

Uploaded by

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

Java Method Overloading Example

The document contains a Java class named 'Overload' that demonstrates method overloading with three different 'series' methods. The first method calculates the sum of factorials from 1 to 7, the second computes the sum of the reciprocals of numbers from 2 to a given value x, and the third prints a pattern based on two input integers m and n. The main method creates an instance of the class, calls these methods, and interacts with the user for input.

Uploaded by

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

import [Link].

*;
class Overload
{
int series()
{
int s = 0, p = 1;
for(int i = 1; i <= 7; i++)
{
p = p * i;
s = s + p;
}
return s;
}

double series(double x)
{
double s = 0.0;
for(double i = 2.0; i <= x; i++)
{
s = s + 1 / i;
}
return s;
}

void series(int m, int n)


{
for(int i = 1; i <= m; i++)
{
for(int j = 1; j <= n; j++)
{
[Link](i);
}
[Link]();
}
}

public static void main()


{
Scanner sc = new Scanner([Link]);
Overload ob = new Overload();
int s1 = [Link]();
[Link]("Sum of series 1: " + s1);
[Link]("Enter value of x:");
double x = [Link]();
double s2 = [Link](x);
[Link]("Sum of series 2: " + s2);
[Link]("Enter m and n:");
int m = [Link]();
int n = [Link]();
[Link](m, n);
}
}

You might also like