条件语句case:求所有满足如下条件的四位数:千位上的数字大于百位数字,百位数字大于十位数字,十位数字大于个位数字,并 且千位数字是其他三位数字的和。

public class Demo16{
    public static void main(String[] args){
    int e = 1000;
        for(;e<=9999;e++ ){
        int a = e/1000;
        int b = e/100%10;
        int c = e%100/10;
        int d = e%10;
        if(a>b&&b>c&&c>d&&a==b+c+d){
         System.out.println(e);
                    }
            }
    }
}

这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43117449/article/details/82432269