write a java code to explain else if if


Write a java code to explain Else If ?

if statements are not limited to two cases. You can merge an else and an if to form an else if and test a overall range of mutually exclusive possibilities. For example, here's a version of the Hello program in which handles up to four names on the command line:
// This is the Hello program in Java

class Hello {

public static void main (String args[]) {

if (args.length == 0) {
System.out.println("Hello whoever you are");
}
else if (args.length == 1) {
System.out.println("Hello " + args[0]);
}
else if (args.length == 2) {
System.out.println("Hello " + args[0] + " " + args[1]);
}
else if (args.length == 3) {
System.out.println("Hello " + args[0] + " " + args[1] + " " + args[2]);
}
else if (args.length == 4) {
System.out.println("Hello " + args[0] +
" " + args[1] + " " args[2] + " " + args[3]);
}
else {
System.out.println("Hello " + args[0] + " " + args[1] + " " args[2]
+ " " + args[3] + " and all the rest!");
}

}

}
You can see in which this gets mighty complicated mighty fast. No experienced Java programmer would write code like this. There is a better solution and you'll explore it in the further section.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: write a java code to explain else if if
Reference No:- TGS0284375

Expected delivery within 24 Hours