62,614
社区成员
发帖
与我相关
我的任务
分享
total numbers:
30
total legs:
70
rabbit:5,chicken :25
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("total numbers:");
int total = sc.nextInt();
System.out.println("total legs:");
int legs = sc.nextInt();
for (int chicken = 0; chicken < total; chicken++) {
if (total - chicken == (legs - chicken * 2) / 4 && (legs - chicken * 2) % 4 == 0) {
System.out.println("rabbit:" + (total - chicken) + ",chicken :" + chicken);
}
}
}