1.百千白鸡。
public class Demo15{
public static void main(String[] args){
int x,y,z;
for(x=0;x<=20;x++){
for(y=0;y<=33;y++){
z = 100-x-y;
if(z%3==0 && 5*x+3*y+z/3==100)
System.out.println("公鸡" + x + "只, 母鸡" + y + "只, 小鸡" + z + "只");
}
}
}
}
2.编程判断一个给定年份是否为闰年。
public class Demo12{
public static void main(String[] args){
int[] month01 = {1,3,5,7,8,10,12};
int[] month02 = {4,6,9,11};
int[] month03= {2};
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.print("请输入年份:");
int year = sc.nextInt();
System.out.print("请输入月份:");
int month = sc.nextInt();
int index = 0;
while(index<month01.length){
if(month01[index]==(month)){
System.out.println("这个月有31天");
break;
}
index++;
}
if(index == month01.length){
index = 0;
while(index<month02.length){
if(month02[index]==(month)){
System.out.println("这个月有30天");
break;
}
index++;
}
if(index == month02.length){
index = 0;
while(index<month03.length){
if(month03[index]==(month)){
if ((year % 4 == 0) && !(year % 100 == 0)|| (year % 400 == 0)){
System.out.println(year + "年" + month + "月有29天");break;}
System.out.println(year + "年" + month + "月有28天");break;
}
}
index++;
}
}
}
}
3.学生管理系统。
public class Demo14{
public static void main(String[] args){
java.util.Scanner sc = new java.util.Scanner(System.in);
boolean isLogin = false;
int count=4;
System.out.println("****************************************************");
System.out.println("* *");
System.out.println("* *");
System.out.println("* 欢迎登录北京德润科技班级管理系统 *");
System.out.println("* *");
System.out.println("* *");
System.out.println("****************************************************");
System.out.println();
while(true) {
if(!isLogin){
System.out.println("--请选择操作(相应菜单项前的数字:)");
System.out.println(" 0.登录系统 1.关闭系统");
String input = sc.nextLine();
while(!"0".equals(input) && !"1".equals(input)){
System.out.println("请输入正确的操作代码!\n");
System.out.println("--请选择操作(相应菜单项前的数字:)");
System.out.println(" 0.登录系统 1.关闭系统");
input = sc.nextLine();
}
System.out.println("欢迎登录本系统。请输入您的账号和密码。");
System.out.print("账号:");
String account = sc.nextLine();
System.out.print("密码:");
String password = sc.nextLine();
//假设已经注册的账户是:ljh, 密码是:12345678.
while(!"ljh".equals(account) || !"12345678".equals(password)){
System.out.println("您的账号或密码错误。请重新输入。\n");
if(count==0)
System.exit(0);
System.out.print("账号");
account = sc.nextLine();
System.out.print("密码");
password = sc.nextLine();
count-- ;
isLogin = true;
System.out.println("欢迎您," + account);
}
System.out.println("\n*********************************");
System.out.println("请选择相应的操作:");
System.out.println(" 1.添加新成员 ");
System.out.println(" 2.修改成员信息 ");
System.out.println(" 3.删除指定成员 ");
System.out.println(" 4.查看所有成员 ");
System.out.println(" 5.退出登录 ");
System.out.println(" 6.退出系统 ");
System.out.println("******************************");
System.out.println("\n操作代码");
String operationNo = sc.nextLine();
switch(operationNo){
case "1":
break;
case "2":
break;
case "3":
break;
case "4":
break;
case "5":
isLogin = false;
System.out.println("您已退出系统。\n");
break;
case "6":
System.out.println("欢迎下次光临!bye-bye");
System.exit(0);
break;
default:
break;
}
}
}
}
}