当前位置:首页 > JAVA教程 >

809x??=800x??+9*?? 其中??代表的两位数,8x??的结果为两位数,9x??的结果为3位数。求??代表的两位数,及809x??后的结果。

发布时间:2024-01-11 09:23:36 作者:佚名 阅读:(1)

最近在重温Java的经典实例,接下来云梦编程就为大家分享一下809x??=800x??+9*?? 求??代表的两位数,及809x??后的结果。有需要的小伙伴可以参考一下:

1、题目要求:

809x??=800x??+9*?? 其中??代表的两位数,8x??的结果为两位数,9x??的结果为3位数。求??代表的两位数,及809x??后的结果。

2、程序代码:

    (1)、解法一:

public static void main(String[] args) {
    int number = 0;
    boolean flag = false;
    for (int i = 10; i < 100; i++) {
        if (809 * i == (800 * i + 9 * i)) {
            if (((8 * i) < 100) && ((9 * i) > 99)) {
                flag = true;
                number = i;
                break;
            }
        }
    }
    System.out.println(flag ? "809*" + number + "=" + (809 * number) : "无符合要求的数!");
}

    (2)、解法二:

public class Main {
    public static void main(String[] args) {
        int ab = findTwoDigitNumber();
        int result = 809 * ab;
        System.out.println("??代表的两位数为:" + ab);
        System.out.println("809x??的结果为:" + result);
    }
    
    // 寻找满足条件的两位数
    public static int findTwoDigitNumber() {
        for (int x = 1; x <= 9; x++) {
            int temp = 800 * x + 9 * x;
            if (temp >= 10 && temp <= 99 && 9 * x >= 100 && 9 * x <= 999) {
                return x;
            }
        }
        return -1; // 如果没有找到满足条件的两位数,返回 -1
    }
}

以上就是云梦编程为大家介绍的809x??=800x??+9*?? 求??代表的两位数,及809x??后的结果的程序写法,了解更多相关文章请关注云梦编程网!

© 2023 - 云梦编程网 版权所有 鲁ICP备2021017318号-4