1.输入年份判断是闰年还是平年?
System.out.println("请输入年份:"); Scanner sc=new Scanner(System.in); String ss=sc.nextLine(); int year=Integer.parseInt(ss); if(year%400==0 || (year%4==0 && year%100!=0)){ System.out.println(year+"年是闰年"); }else{ System.out.println(year+"年是平年"); }
2.输入身高体重性别判断身体比例是否正常?
Scanner sex=new Scanner(System.in); System.out.println(" 请输入性别:"); String se=sex.nextLine(); if(se.equals("男")){ System.out.println(" 请输入身高:"); String he=sex.nextLine(); int sg=Integer.parseInt(he); System.out.println(" 请输入体重:"); String we=sex.nextLine(); int tz=Integer.parseInt(we); int bz = sg-100; if(bz-tz>=-3 && bz-tz<=3){ System.out.println("正常"); }else{ System.out.println("不正常"); } }else if(se.equals("女")){ System.out.println(" 请输入身高:"); String he=sex.nextLine(); int sg=Integer.parseInt(he); System.out.println(" 请输入体重:"); String we=sex.nextLine(); int tz=Integer.parseInt(we); int bz = sg-110; if(bz-tz>=-2 && bz-tz<=2){ System.out.println("正常"); }else{ System.out.println("不正常"); } }else{ System.out.println("你走开!"); }
3.输入三个数,输出最大值
System.out.println("其输入三个数:"); Scanner v=new Scanner(System.in); String a=v.nextLine(); int a1=Integer.parseInt(a); String b=v.nextLine(); int b1=Integer.parseInt(b); String c=v.nextLine(); int c1=Integer.parseInt(c); int big; if(a1>b1){ big=a1; if(a1>c1){ big=a1; System.out.println(big); }else{ big=c1; System.out.println(big); } }else{ big=b1; if(b1>c1){ big=b1; System.out.println(big); }else{ big=c1; System.out.println(big); } }
4.登录验证
Scanner scan=new Scanner(System.in); System.out.println("请输入用户名:"); String yhm=scan.nextLine(); System.out.println("请输入密码:"); String mm=scan.nextLine(); if(yhm.equals("admin")){ if(mm.equals("admin")){ System.out.println("恭喜您登陆成功"); }else{ System.out.println("对不起您输入的密码不正确"); } }else{ System.out.println("对不起您输入的用户名不正确"); if(mm.equals("admin")){ }else{ System.out.println("对不起您输入的密码不正确"); } }