In: Computer Science
5. Write a method to accept five int parameters and return the largest of the five.
Example: largest(45, 13, 65, 19, 23) returns 65. Java Program (METHOD ONLY!!!)
Method 1:-
public int max(int a,int b,int c,int d,int e)
{
return Math.max(a,Math.max(b,Math.max(c,Math.max(d,e))));
// OR
return Math.max(Math.max(Math.max(Math.max(a,b),c),d),e);
}
Method 2:-
public int largest(int a,int b,int c,int d,int e)
{
if(a>b && a>c && a>d
&& a>e)
result=a;
else if(b>a && b>c &&
b>d && b>e)
result=b;
else if(c>a && c>b
&& c>d && c>e)
result=c;
else if(d>a && d>b
&& d>c && d>e)
result=d;
else result =e;
return result;
}
kindly try any of the methods and please feel free to
comment if you get any further help......please give a like if you
find it needfull...