-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh5_5.java
More file actions
36 lines (29 loc) · 795 Bytes
/
Copy pathCh5_5.java
File metadata and controls
36 lines (29 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Scanner;
public class Ch5_5
{
/*
* 参数head,头数
* 参数foot,脚数
* 参数tu,存放兔子的个数
* 参数ji,存放鸡的个数
*/
static void JTTL(int head,int foot,int[] tu,int[] ji)
{
tu[0]=(foot-2*head)/2; //兔子的数量
// ji[0]=head-tu[0]; //鸡的数量
ji[0]=2*head-foot/2; //鸡的数量
}
public static void main(String[] args)
{
int[] ji={0},tu={0};
int head,foot;
System.out.printf("鸡兔同笼问题求解!\n");
System.out.printf("输入头数:");
Scanner input=new Scanner(System.in);
head=input.nextInt(); //输入头数
System.out.printf("输入脚数:");
foot=input.nextInt(); //输入脚数
JTTL(head,foot,tu,ji);
System.out.printf("鸡有:%d只,兔子有:%d只。\n",ji[0],tu[0]);
}
}