Java开发中经典的小实例-(swich(){case:参数break;default: break;})
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java开发中经典的小实例-(swich(){case:参数break;default: break;})相关的知识,希望对你有一定的参考价值。
import java.util.Scanner;
public class Test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input =new Scanner(System.in);
System.out.println("pleace input your sex:(1=man,2=women)");
String sex=input.next();
char ch=sex.charAt(0);
switch(ch){
case ‘a‘:
System.out.println("men");
break;
case ‘b‘:
System.out.println("women");
break;
default:
System.out.println("red women");
break;
}
}
}
------------------------------------------------------------------------------------------
import java.util.Scanner;
public class Test7 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("please chooice menu:(1=用户管理,2=单位档案,3=开户行,4=会计期间)");
int chooice = input.nextInt();
switch (chooice) {
case 1:
System.out.println("用户管理");
break;
case 2:
System.out.println("单位档案");
break;
case 3:
System.out.println("开户行");
break;
case 4:
System.out.println("会计期间");
break;
default:
System.out.println("input error!");
}
}
}
以上是关于Java开发中经典的小实例-(swich(){case:参数break;default: break;})的主要内容,如果未能解决你的问题,请参考以下文章
Java开发中经典的小实例-(if(参数){}else{})