package lianxi; import java.util.Random; import java.util.Scanner; public class Menu { public static void main(String[] args) { mainMenu(); } public static void mainMenu() { Scanner sc = 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 = sc.nextInt(); switch (i) { case 1: login(); break; case 2: zhuce(); break; case 3: choujiang(); break; case 4: read(); break; case 5: exit(); break; } } private static void login() { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); System.out.println("输入用户名"); String uname = sc.next(); System.out.println("输入密码"); String upwd = sc.next(); if (uname.equals("tzy") && upwd.equals("816")) { System.out.println("登录成功"); } else { System.out.println("登录失败"); } returnMain(); } private static void zhuce() { Scanner zc = new Scanner(System.in); System.out.println("输入用户名:"); String name = zc.next("tzy"); System.out.println("输入密码"); String psw = zc.next("816"); System.out.println("注册成功!"); returnMain(); } private static void choujiang() { Scanner hy = new Scanner(System.in); System.out.print("请输入四位会员号:"); Random sj = new Random(); int sjs = sj.nextInt(); int hynum = hy.nextInt(); if(hynum/100%10==sjs) { System.out.println("您是星选会员!"); }else { System.out.println("您不是星选会员!"); } returnMain(); } private static void read() { System.out.println("请选择故事:"); System.out.println("1.丑小鸭"); System.out.println("2.卖火柴的小女孩"); Scanner rd = new Scanner(System.in); int gs = rd.nextInt(); switch(gs) { case 1: System.out.println("您选择的是丑小鸭"); break; case 2: System.out.println("您选择的是卖火柴的小女孩"); break; default: System.out.println("重新选择。"); read(); }returnMain(); } private static void exit() { System.out.println("欢迎下次使用!再见!"); } public static void returnMain(){ System.out.println("是否返回主菜单?Y/N"); Scanner sc = new Scanner(System.in); if (sc.next().equalsIgnoreCase("Y")) { mainMenu(); }else{ System.out.println("谢谢使用"); } } }
package com.xuexiao; import java.util.Scanner; public class jc { /*2.编写一个方法,求整数n的阶乘,例如5的阶乘是1*2*3*4*5。*/ public static void main(String[] args) { // TODO Auto-generated method stub jcmain(); } private static void jcmain() { Scanner sc = new Scanner(System.in); System.out.print("请输入一个数:"); int sj = sc.nextInt(); int sum=1; for(int i =sj ;i>=1;i--) { sum*=i; }System.out.println(sum); } }
package com.xuexiao; import java.util.Scanner; public class near { public static void main(String[] args) { // TODO Auto-generated method stub /*3..编写一个方法,判断该年份是平年还是闰年*/ near(); } private static void near() { Scanner sc = new Scanner(System.in); System.out.println("请输入一个年份:"); int nf = sc.nextInt(); if(nf %400 ==0 ||(nf %4==0&& nf%100!=0)) { System.out.println("闰年"); }else { System.out.println("平年"); } } }