JAVA 연습장
JAVA 반복문(while) 활용하여 코딩 연습(마크다운 사용하여 글 작성!!)
개발 일기
2021. 6. 3. 18:16
안녕하세요. 이번에는 while 반복문을 배운 뒤 활용하여
☆, ★을 반복 조건에 맞추어 찍어보는 코딩을 해보았습니다!!
그리고 제가 티스토리에서 개발 관련 블로그를 여러 곳 보다가
티스토리에서 마크다운을 지원한다고 하여 앞으로는 개발 양식에 맞추어 올리도록 하겠씁니다!!!
public class WhileNested {
public static void main(String[] args) {
System.out.println("1.-----------------------");
/*
★★★★★
★★★★★
★★★★★
★★★★★
★★★★★
*/
int i=0;
while(i<5) {
int j=0;
while(j < 5) {
System.out.printf("%s[%d,%d]","★",i,j);
j++;
}
System.out.print("\n");
i++;
}
int z=0;
while(z<5) {
int j=0;
while(j < 5) {
System.out.printf("%s","☆",i,j);
j++;
}
System.out.print("\n");
z++;
}
System.out.println("2.-----------------------");
/*
☆★★★★
★☆★★★
★★☆★★
★★★☆★
★★★★☆
*/
i=0;
while(i<5) {
int j = 0;
while(j<5) {
if(i==j) {
System.out.printf("%s","☆");
}else {
System.out.printf("%s","★");
}
j++;
}
System.out.print("\n");
i++;
}
System.out.println("3.-----------------------");
/*
☆☆☆☆☆
★☆☆☆☆
★★☆☆☆
★★★☆☆
★★★★☆
*/
i=0;
while(i<5) {
int j = 0;
while(j<5) {
if(i<=j) {
System.out.printf("%s","☆");
}else {
System.out.printf("%s","★");
}
j++;
}
System.out.print("\n");
i++;
}
System.out.println("4.-----------------------");
/*
★
★★
★★★
★★★★
★★★★★
*/
int e = 0;
while(e<5) {
int f = 0;
while(f<5) {
if(e>=f) {
System.out.printf("★");
} f++;
}
System.out.println();
e++;
}
}
}