题解 | #百钱买百鸡问题#--流程控制

百钱买百鸡问题

https://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int maxA = 100 / 5;
        int maxB = 100 / 3;
        for (int i = 0; i <= maxA; i++) {
            for (int j = 0; j <= maxB; j++) {
                int sum = 5 * i + j * 3;
                if (sum <= 100) {
                    int c = (100 - sum) * 3;
                    if (i + j + c == 100) {
                        System.out.print(i + " " + j + " " + c);
                        System.out.println();
                    }
                }
            }
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务