一,百钱买百鸡问题
我国古代数学家张丘建在《算经》一书中曾提出过著名的“百钱买百鸡”问题,该问题叙述如下:鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一;百钱买百鸡,则翁、母、雏各几何?`
public class Test {
public static void main(String[] args) {
int q = 0;
for (int w = 0; w <= 20; w++) {
for (int e = 0; e <= 33; e++) {
int r = 100 - w - e;
if (r % 3 == 0 && (5 * w + 3 * e + r / 3 == 100)) {
q = ++q;
System.out.println("方案" + q);
System.out.println("公鸡" + q + "母鸡" + e + "小鸡" + r);
}
}
}
}
}
二,多次输入数字,得到其对应月份
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int month;
Scanner user=new Scanner(System.in);
System.out.println("请输入一个月份数字");
while (user.hasNext()){
month=user.nextInt();
switch (month) {
case 1:
System.out.println(month + "属于春季");
break;
case 2:
System.out.println(month + "属于春季");
break;
case 3:
System.out.println(month + "属于春季");
break;
case 4:
System.out.println(month + "属于夏季");
break;
case 5:
System.out.println(month + "属于夏季");
break;
case 6:
System.out.println(month + "属于夏季");
break;
case 7:
System.out.println(month + "属于秋季");
break;
case 8:
System.out.println(month + "属于秋季");
break;
case 9:
System.out.println(month + "属于秋季");
break;
case 10:
System.out.println(month + "属于冬季");
break;
case 11:
System.out.println(month + "属于冬季");
break;
case 12:
System.out.println(month + "属于冬季");
break;
default:
System.out.println("输入的数字不在1-12内,请重新输入");
}
}
}
}