Why not to make this function more simple?

Viewed 45

I'm learning Java these weeks.

Here is a function code for my course:

public class MethodCall
{
   public static void main(String[] args)
   {
      int a = 5, b = 7;
      int m = min(a, b);
      System.out.println("Minimum is "+ m);
   }

   public static int min(int c, int d)
   {
      int m2;
      if (c < d)
           m2 = c;
      else
           m2 = d;

      return m2;
   }
}

Why do I need to use extra variables: c and d?

Why not to write this code like this:

public class MethodCall
{
    public static void main(String[] args)
    {
        int a = 5, b = 7;
        int m = min(a, b);
        System.out.println("Minimum is "+ m);
    }

    public static int min(int a, int b)
    {
        int m2;
        if (a < b)
            m2 = a;
        

etc.

?

The result is the same and the code isn't redundant, is it?

0 Answers
Related