主页 > 知识库 > 网络编程 > JSP/Java >

java 鸡兔同笼问题

来源:中国IT实验室 作者:佚名 发表于:2013-05-22 10:52  点击:
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
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;
  }
  }

    有帮助
    (1)
    100%
    没帮助
    (0)
    0%