Click here to watch in Youtube :
https://www.youtube.com/watch?v=eAltL-yfSvA&list=UUhwKlOVR041tngjerWxVccw
class SwitchDemo { public static void main(String[] args) { String month = "march"; int monthNumber = 0; /* * In Java SE 7 and later, you can use a String object in the switch * statement's expression. */ switch (month) { case "january": monthNumber = 1; break; case "february": monthNumber = 2; break; case "march": monthNumber = 3; break; case "april": monthNumber = 4; break; case "may": monthNumber = 5; break; case "june": monthNumber = 6; break; case "july": monthNumber = 7; break; case "august": monthNumber = 8; break; case "september": monthNumber = 9; break; case "october": monthNumber = 10; break; case "november": monthNumber = 11; break; case "december": monthNumber = 12; break; default: monthNumber = 0; break; } System.out.println("month number : " + monthNumber); } }
month number : 3
https://sites.google.com/site/javaee4321/java/ControlFlowDemoSwitch-String-App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ControlFlowDemoSwitch-String-App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/08783475a968761a2cf4b3fc7275842653545b35/BasicJava/ControlFlowDemoSwitch-String-App/?at=master
See also:
No comments:
Post a Comment