Prev Main Next

Creating Functions That Act Like Expressions: More Than One Argument

To use more than one argument (or parameter), show all of the parameters, separated by commas, each of the form type name.


Example

Here is an function that returns the smaller of two integers.

  public static int min(int a, int b)
  {
    if(a < b) return a;
    else return b;
  }

Question. What is wrong with the following function definition?

  public static int min(int x, int y)
  {
    if(x < y) return x;
    else if(y < x) return y;
  }
Answer[33]


Prev Main Next