232k views
4 votes
Write the definition of a method min that has two int parameters and returns the smaller.

User Zapata
by
8.3k points

1 Answer

4 votes
public class ExampleMinNumber {
public static void main(String[] args) {
int a = 11;
int b = 6;
int c = minFunction(a, b);
System.out.println("Minimum Value = " + c);
}

/** returns the minimum of two numbers */
public static int minFunction(int n1, int n2) {
int min;
if (n1 > n2)
min = n2;
else
min = n1;
return min;
}
}
java 8.0
User Wiseman
by
7.9k points