测试1

1.从键盘录入任意两个三位数,分别是最大值和最小值,再改范围内输出一个三位数,要求该三位数每一位的数字立方加起来等于这个数的本身。

package test;

public class Test {
    public static void main(String[] args) {
        int x = 100; int y = 500;
        for(int num = x; num < y; num++) {
            int a = num % 10;
            int b = num /10 %10;
            int c = num/100%10;
            if(Math.pow(a,3) + Math.pow(b, 3)+Math.pow(c, 3) == num) {
                System.out.println(num);
            }
        }
    }
}

2.某钢厂在对成品钢卷进行排列并存放,假设钢卷编号分别为NO.3,NO.4,NO.5,NO.6,NO.7,NO.8,请用你熟悉的语法编写一个函数,打印出所有不同的组合排列,如:345678, 876543等,要求:NO.4号钢卷不能在第3位,NO.3和NO.5号钢卷不能相邻

package test;

public class Test2 {
    private static String[] mustNumber = {"3","4","5","6","7","8"};
    private static boolean number(String str) {
        for(String num : mustNumber) {
            if(str.indexOf(num) < 0) {
                return false;
            }
            if(str.charAt(2)==4) {
                return false;
            }
            if(str.indexOf("35") >=0 || str.indexOf("53") >= 0) {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        int count = 0;
        for(int i = 345678;i <=876543;i++) {
            if(number(String.valueOf(i))) {
                System.out.println(i);
                count++;
            }
        }
        System.out.println(count);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值