vendredi 3 mars 2017

java If Else is not working as expected [on hold]

public class Test1 {
    static boolean h(int a)
    { 
        //boolean f = false;
        if(a>4)
        {
            return true;
        }
        else if (a>1)
        {
            System.out.println("ppppp");
           return true;
        }

        System.out.println(".....");
        System.out.println("####");
        return false;
        //return f;

    }

    public static void main(String[] args) 
    {
        int a=2;
        if(a==2)
        {System.out.println("2222");
        String s=new Test1().p();
        System.out.println(s);
        }

    }

}

output is:2222 pppp true

i want to ask why in above code the code after else statement in not being read (System.out.println("....."); System.out.println("####"); return false; ).....?

Aucun commentaire:

Enregistrer un commentaire