DEV Community

Jeya Lakshmi
Jeya Lakshmi

Posted on

NestedIf

package conditionalStatement;

public class NesIfeleigbleVoteAndAlive {
    static boolean alive = true;
    static int age = 100;
    static String country = "tamilnadu";

    public static void main(String[] args) {

        if (alive == true && country == "tamilnadu") {
            System.out.println("Alive");
            if (age >= 18) {
                System.out.println("Eligible");
            } else {
                System.out.println("not Eligible ");
            }
        } else if (country=="andra") {
            System.out.println("Other country not allowed");
        }
        else {
            System.out.println("Not alive");
        }
    }

}

Example 2:
Enter fullscreen mode Exit fullscreen mode

package conditionalStatement;

public class NesLoginAndPassword {
static String userName = "jdeya";
static int Password = 2353;

public static void main(String[] args) {
    NesLoginAndPassword nl = new NesLoginAndPassword();
    System.out.println(nl.userName);


    if(userName=="jeya") {
        if(Password==235) {
        System.out.println("user created succesfully");
        }
        else if(Password==353) {
            System.out.println("user createed 353");
        }
        else {
            System.out.println("Passwored wrong");
        }
    }
    else {
        System.out.println("user name wrong name entry");
    }
}
Enter fullscreen mode Exit fullscreen mode

}


Enter fullscreen mode Exit fullscreen mode

Example 3:

package conditionalStatement;

public class NesNumberIsPostivieAndEven {
    public int number = 109;

    public static void main(String[] args) {

        NesNumberIsPostivieAndEven nb = new NesNumberIsPostivieAndEven();

        if (nb.number > 0) {
            System.out.println("positive");
            if(nb.number%2==0) {
                System.out.println("even");
            }
            else {
                System.out.println("odd");
            }
        } else {
            System.out.println("negative");
        }

    }

}
Enter fullscreen mode Exit fullscreen mode

Example 4:

package conditionalStatement;

public class NesVowelAndUpperCase {
    static char num = 'w';

    public static void main(String[] args) {
        NesVowelAndUpperCase nv = new NesVowelAndUpperCase();
 if(Character.isLetter(num)) {

 }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)