samedi 31 octobre 2015

How do I return my string inside an if statement?

public static String  mixColors1(String x, String y)
{
    String red="red";
    String yellow="yellow";
    String blue="blue";
    String color = null;//this line... is an issue
    if(red == x && yellow == y || red == y && yellow == x)//if red&yellow selected
        color = "orange";//return orange

    else if(red == x && blue == y || red == y && blue == x)//if red&blue selected
        color = "purple";//return purple

    else if(yellow == x && blue == y || yellow == y && blue == x)//if blue&yellow selected
        color = "green";//return green

    return color;
}

Aucun commentaire:

Enregistrer un commentaire