用while和for循环输出1-1000之间能被5整除的数,且每行输出3个。

 1 /*测试for 
 2  * 用while和for循环输出1-1000之间能被5整除的数,且每行输出3个。
 3  */
 4 public class TestFor {
 5     public static void main(String[] args){
 6         for(int i = 1;i<=1000;i++){
 7             if(i%5==0){//能被5整除 的整数
 8                 System.out.print(i+"\t");//print不会隔行打印;\t制表符把数据分开(空格 亦可)
 9             }
10             if(i%15==0)//每行输出3个:每行第三个数都是以15的倍数结尾的;
11                 System.out.println();//println相当于\n;
12         }
13             
14         
15     }
16 
17 }

 

posted @ 2018-02-05 23:37  zbgghost  阅读(2748)  评论(0编辑  收藏  举报