- package Two;
- import java.util.Scanner;
- public class Gao
- {
- public static void main(String args[]) {
- System.out.println("---------鸡兔同笼问题------");
- int head, foot;
- int ji[] = { 0 }, tu[] = { 0 };
- System.out.print("输入头数:");
- Scanner scanner = new Scanner(System.in);
- head = scanner.nextInt();
- System.out.print("输入脚数:");
- foot = scanner.nextInt();
- JTTL(head,foot,tu,ji);
- System.out.println("鸡有"+ji[0]+"个"+","+"兔有"+tu[0]+"个");
- }
-
- private static void JTTL(int head, int foot, int[] tu, int[] ji)
- {
- // TODO Auto-generated method stub
- tu[0]=foot/2-head;
- ji[0]=2*head-foot/2;
- }
- }
复制代码 |
|