|
-
Aug 27th, 2006, 11:29 PM
#1
Thread Starter
PowerPoster
Overloaded Methods
Hi...
I want to create 3 overloaded methods for the following code block.
int i1 = 11;
int i2 = 5;
int iTotal = addNumbers(i1,i2); // method 1
System.out.println("iTotal: "+iTotal);
double d1 = 12.0;
double d2 = 3.9;
double dTotal = addNumbers(d1,d2); // method 2
System.out.println("dTotal: "+dTotal);
double mixedTotal = addNumbers(i1,d1); //method 3
System.out.println("mixedTotal: "+mixedTotal);
I done it as follows,
class OverloadMethods
{
public static void main(String args[])
{
int i1 = 11;
int i2 = 5;
int iTotal = addNumbers(i1,i2); // method 1
System.out.println("iTotal: "+iTotal);
double d1 = 12.0;
double d2 = 3.9;
double dTotal = addNumbers(d1,d2); // method 2
System.out.println("dTotal: "+dTotal);
double mixedTotal = addNumbers(i1,d1); //method 3
System.out.println("mixedTotal: "+mixedTotal);
}
static int addNumbers(int i1,int i2)
{
return i1 +i2;
}
static double addNumbers(double d1,double d2)
{
return d1 + d2;
}
static double addNumbers(int i1,double d1)
{
return (double)i1 + d1;
}
}
It’s ok for me. Now what I want to do it need to write a 4th method, let say orderedOutput() that take three totals as parameters (iTotal,dTotal,mixedTotal) and displays them from greatest to least.
I’m confusing how to display all these three totals in a single method. Please can someone help on this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|