public static void main(String[] args) { mainMenu(); } public static void mainMenu() { Scanner input = new Scanner(System.in); System.out.println("1.登录"); System.out.println("2.注册"); System.out.println("3.幸运抽奖,输入四位会员卡号,如果百位等于系统随机数,就是星运会员.否则不是."); System.out.println("4.看小故事,"); System.out.println("5.退出系统"); System.out.println("请选择"); int i = input.nextInt(); switch (i) { case 1: login(); break; case 2: zhuce(); break; case 3: choujiang(); break; case 4: sgs(); break; case 5: break; } } private static void sgs() { System.out.println("一个小故事"); returnMain(); } private static void choujiang() { Random r=new Random(); int i1 = r.nextInt(10); System.out.println("请输入四位会员卡号"); Scanner input = new Scanner(System.in); int i = input.nextInt(); if (i1==i%1000/100){ System.out.println("恭喜你中奖了"); }else { System.out.println("很遗憾你没有中奖"); } returnMain(); } private static void login() { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); System.out.println("输入用户名"); String uname = input.next(); System.out.println("输入密码"); String upwd = input.next(); if (uname.equals("zs") && upwd.equals("123")) { System.out.println("登录成功"); } else { System.out.println("登录失败"); } returnMain(); } public static void returnMain(){ System.out.println("是否返回主菜单?Y/N"); Scanner input = new Scanner(System.in); if (input.next().equalsIgnoreCase("Y")) { mainMenu(); }else{ System.out.println("谢谢使用"); } } public static void zhuce(){ System.out.println("请输入用户名"); Scanner input = new Scanner(System.in); String line = input.nextLine(); System.out.println("请输入密码"); int i = input.nextInt(); login(); } }
public static void cj() { int sum=1; for(int i=1;i<=4;i++) { sum*=i; } System.out.println("4的阶乘="+sum); } public static void main(String[] args){ // TODO 自动生成的方法存根 cj(); } }
public static void main(String[] args) { prn(2018); } public static void prn(int year) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { System.out.println(year + "年是闰年"); } else { System.out.println(year + "年不是闰年"); } }