@Test
public void test3(){
System.out.println("请输入数字:");
Scanner src2 = new Scanner(System.in);
int num = src2.nextInt();
switch(num){
case 0:
System.out.println("星期一");
break;
case 1:
System.out.println("星期二");
break;
case 2:
System.out.println("星期三");
break;
case 3:
System.out.println("星期四");
break;
case 4:
System.out.println("星期五");
break;
case 5:
System.out.println("星期六");
break;
case 6:
System.out.println("星期日");
break;
default:
System.out.println("请输入0-6之间的数字");
}
}
@Test
public void test2(){
//做一个登录效果,输入用户名和密码,如果用户名是:张三
//密码是:123 就提示登录成功,否则提示登录失败
System.out.println("请输入用户名:");
Scanner src1 = new Scanner(System.in);
String name = src1.next();
int password = 123;
if("张三".equals(name)){ /****正确写法,正确写法,正确写法,正确写法****/
if( password == 123){
System.out.println("密码正确");
}else{
System.out.println("密码错误");
}
System.out.println("登陆成功!!!");
}else{
System.out.println("用户名输入错误");
}
}
@Test
public void test3(){
double num1 = 0;
double num2 = 0;
String flag = "";//符号
double result = 0;//运算结果
System.out.println("请输入一个数:");
num1 = new Scanner(System.in).nextDouble();
System.out.println("请再输入一个数:");
num2 = new Scanner(System.in).nextDouble();
System.out.println("请输入一个符号(+ - * /)");
flag = new Scanner(System.in).next();
if("+".equals(flag)){
result = num1 + num2;
}else if("-".equals(flag)){
result = num1 - num2;
}else if("*".equals(flag)){
result = num1 * num2;
}else if("/".equals(flag)){
if(num2 != 0){
result = num1 / num2;
}else{
System.out.println("除数不能为0");
}
}else{
System.out.println("请按要求输入运算符号");
}
System.out.println("程序的运行结果为:"+result);
}
@Test
public void test1(){
System.out.println("请输入月份:");
Scanner src = new Scanner(System.in);
int month = src.nextInt();
switch(month){
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10 :
case 12 :
System.out.println(month+"月有31天");
break;
case 2 :
System.out.println(month+"月有28天");
break;
case 4 :
case 6 :
case 11 :
System.out.println(month+"月有30天");
break;
default:
System.out.println("请正确输入月份!!!");
}
}
@Test
public void test4(){
//员工根据A B C 等级进行加薪,分别为500 300 100
System.out.println("请输入你的工资:");
Scanner src4 = new Scanner(System.in);
int salary = src4.nextInt();
System.out.println("请输入你的等级(A B C):");
String grade = src4.next();
int A = 500;
int B = 300;
int C = 100;
switch(grade){
case "A" :
System.out.println("您的工资为:"+(salary+A));
break;
case "B" :
System.out.println("您的工资为:"+(salary+B));
break;
case "C" :
System.out.println("您的工资为:"+(salary+C));
break;
}
src4.close();
}
@Test
public void test2(){
System.out.println("请输入月份:");
Scanner src1 = new Scanner(System.in);
int jije = src1.nextInt();
switch(jije){
case 3:
case 4:
case 5:
System.out.println("春季");
break;
case 6:
case 7:
case 8:
System.out.println("夏季");
break;
case 9:
case 10:
case 11:
System.out.println("秋季");
break;
case 12:
case 1:
case 2:
System.out.println("冬季");
break;
default :
System.out.println("请输入1-12之间的月份");
}
}