public class Snap {
public static void main(String[] args) {
for (int x = 0; x <= 100 / 5; x++) {
for (int y = 0; y <= 100 / 3; y++) {
int z = 100 - x - y;
if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100) {
System.out.println("鸡翁:"+x + "," +"鸡母:"+ y + ","+"鸡雏:" + z);
}
}
}
}
}
public class Test4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你准备花的钱数");
int a = sc.nextInt();
System.out.println("请输入你准备买的鸡的只数");
int b = sc.nextInt();
getCount(a,b);
}
public static int[] getCount(int a ,int b){
int[] arr = new int[3];
int x=arr[0];//鸡翁
int y=arr[1];//鸡母
int z=arr[2];//鸡雏
for(x=0;x<=a/5;x++){
for(y=0;y<=a/3;y++){
z=b-x-y;
if(z%3==0&&5*x+3*y+z/3==a){
System.out.println(x+","+y+","+z);
}
if(x+y+z!=b&&5*x+3*y+z/3!=a){
System.out.println("输入数据有误");
}
}
arr[0]=x;
arr[1]=y;
arr[2]=z;
}
return arr;
}
}
虽然敲出了代码,我自己可能觉得没毛病,如果有错还是希望大佬们指出来,毕竟人不能太膨胀了,哈哈哈哈..........