案例:统计(水仙花)

案例:统计(水仙花)

//案例:统计(for循环)
//需求:统计水仙花数一共有多少个,并在控制台输出水仙花的个数
public class HelloWorld{
    
    
    public static void main (String[] args){
    
    
        int count = 0;
        for(int i=100; i<=999; i++){
    
    
            int a = i%10;
            int b = i/10%10;
            int c = i/10/10%10;
            if(a*a*a + b*b*b + c*c*c  == i){
    
    
                count++;
            }
        }
        System.out.println("水仙花共有"+count+"个");
    }
}

//while循环语句
public class HelloWorld{
    
    
    public static void main(String[] args){
    
    
        int j = 1;
        while(j<=5){
    
    
            System.out.println("HelloWorld");
            j++;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/taoyingle/article/details/115077276