public static String answer; public static void main(String[] args) { Scanner input=new Scanner(System.in); boolean loginFlag=false; boolean reGister=false; do{ System.out.println("1.注册"); System.out.println("2.登录"); System.out.println("3.抽奖"); System.out.println("请选择"); int select=input.nextInt(); switch (select){ case 1://register reGister = register(input); break; case 2://login loginFlag=login(input,reGister); break; case 3://loterry loterry(input,loginFlag); break; default: System.out.println("请输入有效选择"); } System.out.println("是否继续?"); answer=input.next();} while ("y".equals(answer)); System.out.println("成功退出"); input.close(); } public static String num; public static String password; //定义全局变量,不然注册时候的账号和密码不能调用出来 public static boolean login(Scanner input,boolean registerFlag){ //与注册的账号密码进行比较 if(!registerFlag){ System.out.println("请先注册"); return false; } int count=3; for (;count>0;) { count--; System.out.println("请输入登录账号:"); String numLogin=input.next(); System.out.println("请输入登录密码:"); String passwordLogin=input.next(); if (numLogin.equals(num) &&passwordLogin.equals(password)){ break; } if(count==0) return false; System.out.println("账号或密码不符,还剩下" + (count) + "次机会"); } System.out.println("登陆成功"); return true; } public static boolean register(Scanner input){ System.out.println("请输入注册账号:"); num=input.next(); System.out.println("请输入注册密码:"); password=input.next(); long cID=(long)(Math.random()*9000+1000); System.out.println("账号"+num); System.out.println("密码"+password); System.out.println("卡号"+cID); return true; } public static void loterry(Scanner input, boolean loginFlag){ //登陆成功之后的操作 if(!loginFlag){ System.out.println("请先登录"); return; } System.out.println("请输入卡号"); long cardId=input.nextInt(); int [] lucy=new int[5]; for (int i = 0; i < 5; i++) { lucy[i]=(int)(Math.random()*9000+1000); } System.out.println("大奖卡号"+Arrays.toString(lucy)); for(int i=0;i<5;i++){ if(lucy[i]==cardId){ System.out.println("恭喜您中奖"); return; } } System.out.println("很遗憾您没有中奖");}
标签:抽奖,int,System,static,println,input,幸运,out From: https://www.cnblogs.com/Liku-java/p/16792039.html