구구단과 '*'을 이용한 도형 만들기는 반복문의 꽃입니다.
public class GugudanTest {
public static void main(String[] args) {
//다중 for문
System.out.println("=======================");
System.out.println("다중 for 문");
System.out.println("=======================");
for(int i=2;i<10;i++){
System.out.print(i+"단 : ");
for(int j=1;j<10;j++){
int sum=i*j;
System.out.print(i+"*"+j+"="+sum+" ");
//i값 1, j값은 2로 변경후 System.out.print(j+"*"+i+"="+sum+" ");
}
System.out.println();
}
//do~while문, 2단.
System.out.println("=======================");
System.out.println("do~while문, 2단");
System.out.println("=======================");
int j = 1;
do{
System.out.println(2+"*"+j+"="+2*j);
j++;
}while(j<=9);
//while 문, 2단
System.out.println("=======================");
System.out.println("while 문, 2단");
System.out.println("=======================");
int j2 = 1;
while(j2<=9){
System.out.println(2+"*"+j2+"="+2*j2);
j2++;
}
}
}
'콩's EDUCATION > 콩's JAVA_RUN' 카테고리의 다른 글
피보나치 수열 (0) | 2014.05.09 |
---|---|
1-20까지 정수중 2, 3의 배수가 아닌 정수의 갯수와 합계 (0) | 2014.05.09 |
1부터 10까지 합 while (0) | 2014.05.08 |
1부터 10까지 합 for (0) | 2014.05.08 |
날짜 월 표기 (0) | 2014.05.08 |