Category
- Php
- JAVA
- DOTNET
- Vbscript
- C
- vb
- html
- Mysql
- Oracle
- sql
- Db
- Computer
- Commerce
- Business
- Arts
- Cashier
- Audit
- Banking
- Accounts
- Math
- Physics
- Biology
- Others
Home >> Asked Questions >> JAVA
Q. Switch Case in Java
Answer :
public class SwitcCasehDemo {
public static void main(String[] args) {
int month = 5;
String monthName;
switch (month) {
case 1: monthName= "Jan";
break;
case 2: monthName= "Feb";
break;
case 3: monthString = "March";
break;
case 4: monthString = "April";
break;
case 5: monthName= "May";
break;
case 6: monthName= "June";
break;
case 7: monthName = "July";
break;
case 8: monthName = "August";
break;
case 9: monthName = "Sept";
break;
case 10: monthName = "Oct";
break;
case 11: monthName = "Nov";
break;
case 12: monthName = "Dec";
break;
default: monthName = "Invalid month";
break;
}
System.out.println(monthName);
}
}
public static void main(String[] args) {
int month = 5;
String monthName;
switch (month) {
case 1: monthName= "Jan";
break;
case 2: monthName= "Feb";
break;
case 3: monthString = "March";
break;
case 4: monthString = "April";
break;
case 5: monthName= "May";
break;
case 6: monthName= "June";
break;
case 7: monthName = "July";
break;
case 8: monthName = "August";
break;
case 9: monthName = "Sept";
break;
case 10: monthName = "Oct";
break;
case 11: monthName = "Nov";
break;
case 12: monthName = "Dec";
break;
default: monthName = "Invalid month";
break;
}
System.out.println(monthName);
}
}
Posted By : aman
Most Viewed Questions