for循环例题 以及for增强例题

class fordome6 {
    public static void main(String[] args) {
        //增强for循环
        int[] number = {20,30,40};
        for (int x:number){
            System.out.print(x+ "\t");

        }
        System.out.println("========");
        for (int i=0; i < 5; i++) {
            System.out.print(number[i]+"\t");
        }
    }
}
# for循环例题

package struct;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

public class fordome01 {
public static void main(String[] args) {
//计算奇数和偶数和
int a = 0;
int b = 0;
for (int i=0; i <= 100; i++) {
if (i%2!=0){
a+=i;
}else{
b+=i;
}

    }
    System.out.println(a);//2500
    System.out.println(b);//2550
}

}


package struct;

public class fordome02 {
public static void main(String[] args) {
//用while或for循环输出1~1000之间能被5整除的数;并且每行输出三个

    for (int i=0; i <= 1000; i++) {

        if (i%5==0){
            System.out.print(i+"\t");
        }
        if (i%(5*3)==0){
            System.out.println("\n");//500 505    510
        }

    }
}

}


package struct;

public class fordome3 {
public static void main(String[] args) {
//打印99乘法表
for (int i=1; i <= 9; i++) {
for (int q=1; q < i; q++) {
System.out.print(q+""+i+"="+(iq)+"\t");

        }
        System.out.println();

    }
}

}


1*2=2	
1*3=3	2*3=6	
1*4=4	2*4=8	3*4=12	
1*5=5	2*5=10	3*5=15	4*5=20	
1*6=6	2*6=12	3*6=18	4*6=24	5*6=30	
1*7=7	2*7=14	3*7=21	4*7=28	5*7=35	6*7=42	
1*8=8	2*8=16	3*8=24	4*8=32	5*8=40	6*8=48	7*8=56	
1*9=9	2*9=18	3*9=27	4*9=36	5*9=45	6*9=54	7*9=63	8*9=72	

进程已结束,退出代码 0

### 增强型的for循环
posted @ 2021-04-20 16:12  陈诚成  阅读(154)  评论(0)    收藏  举报