switch...case语句
import java.util.Scanner;
public class Regist {
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
System.out.println("欢迎来到个人博客!");
System.out.println();
System.out.println();
System.out.println();
System.out.println("1.已有账号,登录\n2.注册新账号\n3.退出系统");
System.out.println("请选择:");
int choose = input.nextInt();
switch(choose) {
case 1:
System.out.println("输入用户名:");
String name = input.next();//name 在switch中
System.out.println("输入密码:");
String pass = input.next();
if (name.equals("张三")&&pass.equals("zhangsan")) {
System.out.println("1.查看用户信息\n2.修改密码\n3.充值");
} else {
System.out.println("用户名或者密码错误,请重新登录");
}
break;
case 2:
System.out.println("输入用户名:");
String name1 = input.next();
System.out.println("输入密码:");
String pass1 = input.next();
System.out.println("请确认密码:");
String pass2 = input.next();
if (!name1.equals("张三")&&pass1.equals(pass2)) {
System.out.println("注册成功,请登录");
} else if(name1.equals("张三")){
System.out.println("用户名重复");
} else {
System.out.println("密码不一致");
}
break;
case 3:
break;
default:
System.out.println("输入有误请输入1 ~ 3");
return;
}
}
}