double loop

moon.kick·2025년 2월 14일


: 구구단

뎁스2단계까지만!

for문 :보통때 사용

while문: 무한루프돌릴때

초기화;
while( 조건식 ){
실행문장;
증감식;
}
: 문장과 증감 순서바껴도뎀


package ex0214.제어문;

public class WhileExam011 {

	public static void main(String[] args) {
		//1. 1~ 100가지 한줄로 출력
		//2. A ~Z 까지 한줄로 출력
		//3. 1~ 10 까지  합 구해서 출력
		//4. 1 ~ 100 사이의 7의 배수만 출력 
		//5. 100 ~ 1 사이의 5 의 배수만 출력 
			
		int i=0;
		while( i<=9 ){
			i++;
			System.out.print(i+" " );
		}
		System.out.print("\n");
	
		int j=0;
		while(j<26){
			System.out.print((char)('A'+j)+" ");
			j++;
			}
			System.out.print("\n");
	
	
		int k=0;
		int sum=0;
		while(k<10) {
			k=k+1;
			sum+=k;
			System.out.print(k+" " );
			}
		
		// 1. 1 ~ 100가지 10행 10열로 출력 (for문 안에 for문이용)
		int total= 0;
		while(i<10) {
			i++;
			System.out.print(++total +" ");
			}
		
		System.out.print("\n");
		
				
	//3. 구구단 출력  - 와일문안에 와일문이용
		int row=1;
		while(row<9) {
			row++;   //row행
				int col =1;
				while(col<=9) {
					col++; 
					if(col==5)continue;
					System.out.print(col+"*"+row +" "+"="+(col*row +"\t"));
					}
				
			System.out.println();	
		}
	}
}

do while문 : 잘안씀
초기화;
do{
실행문장;
증감식;
}while( 조건식 );
: 무조건 한번은 실행

profile
@mgkick

0개의 댓글