int boolInt=1; switch (boolInt){ case 0: System.out.println("true = 0"); break; case 1: System.out.println("false = 1"); break; default: System.out.println("Invalid"); break; } // In Java SE 7 and later, you can use a String object in the switch statement's expression String boolStr = "true"; switch (boolStr.toLowerCase()){ case "true": System.out.println("0 = true"); break; case "false": System.out.println("1 = false"); break; default: System.out.println(" Not 0/1 = false"); break; }
Thursday, February 24, 2011
Java Switch Statement
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment