개발 일기
JAVA 반복문(while) 활용하여 코딩 연습(마크다운 사용하여 글 작성!!) 본문
안녕하세요. 이번에는 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++;
}
}
}
'JAVA 연습장' 카테고리의 다른 글
JAVA 코딩 연습 (클래스 생성 후 객체를 활용하여 코딩) (0) | 2021.06.05 |
---|---|
JAVA 반복문(for) 활용하여 코딩 연습(feat. 구구단과 별 줄세우기) (0) | 2021.06.03 |
JAVA 변수 활용하여 코딩 연습하기 4 (feat. if문을 사용하여 유효성 검사&형변환을 통한 소숫점 반올림) (0) | 2021.06.02 |
JAVA 변수 활용하여 코딩 연습하기 3 (숫자형 변수 응용, int, double) (0) | 2021.06.01 |
JAVA 변수 활용하여 코딩 연습하기 2 (세명의 점수 노출) (0) | 2021.05.29 |
Comments