/* */ Click to Join Live Class with Shankar sir Call 9798158723

user-defined function in Java ?


The functions written by the programmer or user to do the specific tasks are called user defined function or programmer defined function.


Q.) Example of user-defined function in Java ?
    public class Addition   
{  
public static void main(String[] args)   
{  
int a = 19;  
int b = 5;  
//method calling  
int c = add(a, b);   //a and b are actual parameters  
System.out.println("The sum of a and b is= " + c);  
}  
//user defined method  
public static int add(int n1, int n2)   //n1 and n2 are formal parameters  
{  
int s;  
s=n1+n2;  
return s; //returning the sum  
}  
}  
Output
The sum of a and b is= 24