31 Java语言基础循环结构while语句的格式和基本使用

循环结构 while 语句的格式

 

1 class Demo_While{
2     public static void main(String args[]){
3         int x =1;
4         while(x<10){
5             System.out.println(x);
6             x++;
7         }
8     }
9 }

 

计算100 到999的水仙花数

 1 class Demo_While{
 2     public static void main(String args[]){
 3         int count = 0;
 4         int i = 100;
 5         while(i<=999){
 6             int a  = i%10; //取得个位
 7             int b  = i/10%10; //取得十位
 8             int c  = i/100; //取得百位
 9 
10             if(i == a*a*a+b*b*b+c*c*c){
11                 count++;
12             }
13         }
14         
15     }
16 }

 

posted @ 2017-01-22 12:56  panw3i  阅读(267)  评论(0编辑  收藏  举报