Here I would like to discuss about methods/functions in java.
Method/Function syntax:
e.g:
public static int funcName(int a, int b){
---------------
---------------
body
---------------
---------------
}
Here,
1) public static :- modifiers
2) int :- return type
3) funcName :- function/method name
4) int a,int b :- formal parameters
Let's look in to a function with 2 parameters that gives minimum of 2 numbers passed,
class MinValue {
public static int minFunction(int n1, int n2){
int min;
if(n1 > n2)
min = n2;
else
min = n1;
return min;
}
public static void main(String [] args){
int a = 14;
int b = 9;
int c = minFunction(a, b);
System.out.println("The min value is : " +c);
}
}
To be continued...
Method/Function syntax:
e.g:
public static int funcName(int a, int b){
---------------
---------------
body
---------------
---------------
}
Here,
1) public static :- modifiers
2) int :- return type
3) funcName :- function/method name
4) int a,int b :- formal parameters
Let's look in to a function with 2 parameters that gives minimum of 2 numbers passed,
class MinValue {
public static int minFunction(int n1, int n2){
int min;
if(n1 > n2)
min = n2;
else
min = n1;
return min;
}
public static void main(String [] args){
int a = 14;
int b = 9;
int c = minFunction(a, b);
System.out.println("The min value is : " +c);
}
}
To be continued...