•用while和for循环输出1-1000之间能被5整除的数,且每行输出3个。
FOR语句:
- public static void main(String[] args) {
- int count=0,j=0;
- for(int i=5;i<=1000;i+=5,j++)
- {
- if(j%3==0 && j!=0)
- System.out.println();
- System.out.print(i+ " ");
- }
- }
WHILE语句:
- public static void main(String[] args) {
- int i=0,j=-1;
- while((i+=5)<=1000)
- {
- if((++j)%3==0 && j!=0)
- System.out.println();
- System.out.print(i+ " ");j++;
- }
- }