题目:输入鸡兔的总数和鸡兔的脚数,输出鸡兔各多少只。
package New.Week1.Math;
import java.util.Scanner;
public class Question {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int m = scan.nextInt();
int i,j;
for(i = 0,j = n;i <= n;i++,j--){
if(i*2+j*4 == m){
System.out.println("鸡:"+i+"只,"+"兔:"+j+"只");
break;
}
}
if(i==n+1){ //判断数据是否有误
System.out.println("输入数据有误");
}
}
}