第1题 从键盘上接受周一至周五每天的学习时间,并计算每日平均学习时间
import java.util.Scanner;
public class HomeWork6_2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double total = 0.0;
for (int i = 1; i <=5 ; i++) {
System.out.print("请输入周"+i+"的学习时间:");
double time=input.nextDouble();
total+=time;
}
double avg = total/5;
System.out.println("周一至周五每日平均学习时间是:"+avg+"小时");
input.close();
}
}
第2题 鸡兔同笼
public class HomeWork6_3 {
public static void main(String[] args) {
for (int chook = 0; chook <= 35; chook++) {
int rabbit = 35-chook;
int foot = 2*chook+4*rabbit;
if(foot==94) {
System.out.println("鸡的数量是:"+chook+"\t"+"兔的数量是:"+rabbit);
}
}
}
}
第3题 FlipFlop
public class HomeWork6_4 {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0) {
if (i % 5 == 0) {
System.out.println("FlipFlop");
} else {
System.out.println("Flip");
}
} else if (i % 5 == 0) {
System.out.println("Flop");
} else {
System.out.println(i);
}
}
}
}
第4题 趣味数学
public class HomeWork6_5 {public static void main(String[] args) {
int men = 0;
int women = 0;
int kids = 0;
System.out.println("可能有以下组合:");
for (men = 0; men <= 30; men++) {
women=20-2*men;
kids=30-men-women;
int money=3*men+2*women+kids;
if(money==50&&women>=0&&kids>=0) {
System.out.println("男人:"+men+"\t"+"女人:"+women+"\t"+"小孩:"+kids);
}
}
}
}