Use if with a series of else statements in Java

if (a == 1) {
    System.out.println("one");
} else if (a == 2) {
    System.out.println("two");
} else if (a == 3) {
    System.out.println("three");
} else {
    System.out.println("invalid");
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.