If, else if, else statement Java Android example

if , else if, else statement with string as a switch statement in Java example source code.

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
		for (int i = 0; i < arrayOfString.length; i++) {
 
			if (arrayOfString[i].equals("Hello"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("people"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("hello"))
				System.out.println(arrayOfString[i]);
			else if (arrayOfString[i].equals("world!"))
				System.out.println(arrayOfString[i]);
			else // default
				System.out.println("Default");
		}
	}
}
/*
Default
Hello
people
Default
hello
world!
Default 
 */
This entry was posted in Android Examples Code and tagged , , , . Bookmark the permalink.


Comments are closed.

10,323 views