JAVA 5강

말하는 감자·2023년 3월 16일
post-thumbnail

2023-03-15


자바 코드 연습


별찍기

☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆

public class Program {
	public static void main(String[] args) {
		for(int i=0;i<10;i++) {
			for(int j=0;j<10;j++) {
				System.out.printf("%c", '☆');
			}
			System.out.println();
		}
	}
}


☆☆
☆☆☆
☆☆☆☆
☆☆☆☆☆
☆☆☆☆☆☆
☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆☆

public class Program {
	public static void main(String[] args) {
		for(int i=0;i<10;i++) {
			for(int j=0;j<i+1;j++) {
				System.out.printf("%c", '☆');
			}
			System.out.println();
		}
	}
}

☆☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆☆
☆☆☆☆☆☆☆
☆☆☆☆☆☆
☆☆☆☆☆
☆☆☆☆
☆☆☆
☆☆

public class Program {
	public static void main(String[] args) {
		for(int i=0;i<10;i++) {
			for(int j=0;j<10-i;j++) {
				System.out.printf("%c", '☆');
			}
			System.out.println();
		}
	}
}

for문 + if문

public class Program {

	public static void main(String[] args) {
		for(int i=0;i<5;i++) 
			if(i==4)
				System.out.printf("%c", 'A' + i);
			else
				System.out.printf("%c,", 'A' + i);
	}

}

반복문 중첩

1 2 3

4 5 6

7 8 9

public class Program {

	public static void main(String[] args) {
		for(int x=0;x<3;x++) 
			for(int y=0;y<3;y++)
				System.out.printf("%d", x*3+y+1);
			System.out.printlf();
	}

}

오목판 출력

┌┬┬┬┬┬┬┬┬┐
├●┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
├┼┼┼┼┼┼┼┼┤
└┴┴┴┴┴┴┴┴┘

public class Program1 {

	public static void main(String[] args) {
		for(int x=1;x<=10;x++) {
			for(int y=1;y<=10;y++) {
				if(x==2 && y==2)
					System.out.printf("%c", '●');
				else if(x==1 && y ==1)
					System.out.printf("%c", '┌');
				else if(x==1 && y==10)
					System.out.printf("%c", '┐');
				else if(x==10 && y==1)
					System.out.printf("%c", '└');
				else if(x==10 && y==10)	
					System.out.printf("%c", '┘');
				else if(x==1)
					System.out.printf("%c", '┬');
				else if(y==1)
					System.out.printf("%c", '├');
				else if(x==10)
					System.out.printf("%c", '┴');
				else if(y==10)
					System.out.printf("%c", '┤');
				else
					System.out.printf("%c", '┼');
			}
			System.out.println();
		}
	}

}

자바에서 다차원 배열을 생성하는 두가지 방법

0개의 댓글