while循环案例

 

 1 class While05{
 2     public static void main(String[ ]args){
 3         //练习1:使用while循环完成输出1------10中的每个数
 4         /*int i =1;
 5         while(i<=10){
 6             System.out.println(i);
 7             i++;
 8         }*/
 9     }
10 }
11 
12 class While06{
13     public static void main(String[ ]args){
14         //练习2:使用while循环完成输出所有的两位数
15         int i =10;
16         while(i<=99){
17             if(i %2 !=0){
18                 System.out.println(i);
19             }
20             i++;
21         }
22         //练习3:使用while循环完成输出50---100范围内所有的奇数
23         
24 
25         //练习3:
26         //第一种方法:
27         /*int i = 51;
28         while(i<=100){
29             System.out.println(i);
30             i +=2;
31         }*/
32 
33         //第二种方法:
34         /*int i = 51;
35         while(i <=100){
36             if(i %2 !=0){
37                 System.out.println(i);
38             }
39             i++;
40         }*/
41     }
42 }
43 
44 class While07{
45     public static void main(String[ ]args){
46     //练习4:使用while循环完成输出所有三位数中能被4整除的数,并且每行显示5个
47     
48         int i = 100,count = 0;
49         while(i <=999){
50             if(i % 4 == 0){
51                 System.out.print(i + "\t");
52                 count ++;
53             }
54             i++;
55             if(count % 5 ==0){
56                 System.out.println();
57             }
58         }
59     }
60 }

 

转载于:https://www.cnblogs.com/penphy/p/10645422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值