05_Using_Multiple_Functions
05_Using_Multiple_Functions
import java.util.*;
class RNC
{
double add(double a, double b)
{
return a + b;
}
double x, y, rs ;
rs = ob.add(x,y);
System.out.println("Sum = " + rs) ;
rs = ob.sub(x,y);
System.out.println("Difference = " + rs) ;
rs = ob.mul(x,y);
System.out.println("Product = " + rs) ;
rs = ob.div(x,y);
System.out.println("Quotient = " + rs) ;
}}
Note : (i) This program uses four functions. Since all the four functions have
different names, there is NO overloading.
(ii) All four functions have parameters with the same names – ‘a’ and ‘b’.
This is perfectly acceptable. You may use different variable names (instead
of ‘a’ and ‘b’) for each function.
Q> Re-write the above program using switch-case (based on the user’s
choice).