_4_3_ループステートメント

1763 ワード

package _4_3_ ;

public class _4_3_Example {

	public static void main(String[] args) {
		// TODO  
		
		//1、while 
		int x=1;
		int sum=0;
		while(x<=10)
		{
			sum=sum+x;
			x++;
		}
		System.out.println("1 10 :sum="+sum);
		
		//2、do.while 
		// , , while 
		int a=61;
		do{
			System.out.println("ok! a==100");
			a--;
		}while(a==60);
		
		//3、for 
		long sum_=0;
		for(int i=2;i<=100;i=i+2)
			sum_=sum_+i;
		System.out.println("0~100 "+sum_);
		//foreach
		int array[]={3,7,1};
		System.out.println(" ");
		for(int x1:array)
			System.out.print(x1+"\t");
	}

}

 
package _4_3_ ;

// while 

public class _4_3_Exercise_1 {

	public static void main(String[] args) {
		// TODO  
		
		String[] aves=new String[]{" "," "," "," "," ",
				" "," "," "," "};
		System.out.println(" :");
		int i=0;
		while(i<aves.length)
			System.out.println(aves[i++]);
	}

}

 
package _4_3_ ;

//for 

public class _4_3_Exercise_2 {

	public static void main(String[] args) {
		// TODO  
		for(int i=1;i<=9;i++)
		{	
			for(int j=1;j<=i;j++)
				System.out.print(j+"*"+i+"="+i*j+" ");
			System.out.println();	
	    }
	}

}