mercredi 28 septembre 2016

Which function is better in order to find the largest integer variable between three variables

I was wondering which function is better in order to find the largest variable between three variables. From what I see the first one has less instructions. Nevermind if we add more variables.

Function 1

 public static void  printLargest(int a, int b, int c)
    {
            if(a > b && a > c)
                System.out.println("a");
            else if(b > a && b > c)
                System.out.println("b");
            else 
                System.out.println("c");
    }

Function 2

public static void printLargest(int a, int b, int c)
    {
        if( a > b)
        {
            if(a < c)
                System.out.println("C");
            else
                System.out.println("A");
        }
        else
        {
            if(b < c)
                System.out.println("C");
            else
                System.out.println("B");
        }
    }

Aucun commentaire:

Enregistrer un commentaire