1-WAP to overload an integer function “over” which will perform the following functions-: A- ADD two numbers B- Factorial of a number C- Find the largest number amon​g 3 numbers.

import java.util.*;
class overload
{
public void over(int a,int b)
{
int c=0;
c=a+b;
System.out.println(c);
}
public void over(int c)
{
int f=1;
for(int i=1;i<=c;i++)
f=f*i;
System.out.println(f);
}
public void over(int d,int e,int f)
{
if(d>e)
System.out.println(d);
else if(e>f)
System.out.println(e);
else if(f>d)
System.out.println(f);
}
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
int a=0,b=0,c=0,d=0,e=0,f=0;
System.out.println("ENTER A");
a=ob.nextInt();
System.out.println("ENTER B");
b=ob.nextInt();
System.out.println("ENTER C");
c=ob.nextInt();
System.out.println("ENTER D");
d=ob.nextInt();
System.out.println("ENTER E");
e=ob.nextInt();
System.out.println("ENTER F");
f=ob.nextInt();
overload obj=new overload();
obj.over(a,b);
obj.over(c);
obj.over(d,e,f);
}
}
/*TO OVOID MULTIPLE INPUT OF NUMBER USING SCANNER CLASS, YOU CAN ALSO USE DIRECT INPUT BY JUST WRITTING THE NAMES OF VARIABLE IN THE MAIN LINE ISTEAD OF String args[]*/


Advertisements