반응형
=+ ,=+ 차이점
1) num += 100 은
num = num + 100 의 줄임 표현이라고 생각하시면 됩니다.
2) =+ 라는 연산자는 없습니다.
num = (+100) 을 적으신 거와 동일합니다.
import java.util.Random;
import java.util.Scanner;
public class Ex13omokProgram2 {
public static void main(String[] args) {
int height = 0;
int width = 0;
int menu;
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("어떤 바둑판 크기를 원하십니까?");
System.out.println("1. (20x20)");
System.out.println("2. (40x20)");
System.out.println("3. (60x30)");
System.out.print(">");
String menu_ = scan.nextLine();
menu = Integer.parseInt(menu_);
if (menu < 1 || menu > 3)
System.out.println("1~3사이의 값을 입력하세요");
else
break;
} // while
switch (menu) {
case 2:
height = 40;
width = 20;
break;
case 3:
height = 60;
width = 30;
break;
case 1:
default:
height = 20;
width = 20;
}// switch
// 비절차식 그리기.
char[][] board = new char[height][width];
// 바둑판 저장하기
for (int y = 1; y <= height; y++) {
for (int x = 1; x <= width; x++) {
board[y - 1][x - 1] = '┼';
}
}
//상판
for (int x = 1; x < width; x++)
board[0][x - 1] = '┬';
//우측벽
for(int y =1; y <=height; y++)
board[y-1][width-1] = '┤';
//밑판
for(int x= 1; x <= width; x++)
board[height-1][x-1] = '┴';
//좌측벽
for(int y =1; y <=height; y++)
board[y-1][width-20] = '├';
//4개의 꼭지점.
board[0][0] = '┌'; //왼쪽상단모서리
board[0][width-1] = '┐'; // 오른쪽상단모서리
board[height-1][width-1] = '┘'; //오른쪽하단 모서리
board[height-1][0] = '└'; //왼쪽하단모서리
// 바둑판 출력하기
// 사용자한테 오목을 입력 받아서 그것을 오목판에 둔다.
//흰돌의 위치 입력
System.out.println("x좌표입력");
int ox = scan.nextInt();
System.out.println("y좌표입력");
int oy = scan.nextInt();
//내용 저장
board[oy-1][ox-1] = '●';
//입력값 받은 바둑판 출력
for (int y = 1; y <= height; y++) {
for (int x = 1; x <= width; x++) {
System.out.printf("%c", board[y - 1][x - 1]);
}
System.out.println();
}
}// class
2차원 배열 정리.
1. 선언 및 초기화.
1) String[][] str = new String[10][10];
str이라는 문자열배열을 생성했다.
우리가 가시적으로 보기쉽게 x,y좌표로 생각하면
0,0 부터 10,10으로 생각한뒤 2차원 좌표로 가시적으로 보아서
오목판을 처리할수있다.
ex) int[][] omok = new int[height][width];
int height =10;
int width =10;
10x10오목판
2) 사실은 메모리에 일렬로 100칸이 있다.
반응형
'웹 프로그래밍 기초 > 자바기반의 웹&앱 응용SW 개발자' 카테고리의 다른 글
| 자바기반의 웹&앱 응용 SW개발자 양성과정 10일차 -19 (0) | 2020.03.10 |
|---|---|
| 자바기반의 웹&앱 응용 SW개발자 양성과정 9일차 -18 (0) | 2020.03.09 |
| 코로나 휴강 대체할 t형의 복습문제13. (0) | 2020.03.08 |
| 코로나 휴강 대체할 t형의 복습문제12. (0) | 2020.03.08 |
| 코로나 휴강 대체할 t형의 복습문제11. (0) | 2020.03.08 |
댓글