2013-09-03 5 views
1

나는 콘솔에서 입력 된 두 개의 정수를 취한 다음이 두 정수 (사각형 크기)의 직사각형 또는 사각형을 표시하는 ascii 아트를 출력하려고합니다. 그러나 모서리는 주 기호와 다른 기호가 될 필요가 있습니다. 그러나 짧은 마술은 원래 기호가 1 ~ 2 개만 있어야합니다 (홀수 또는 짝수로 인해).Ascii Art with Java - 서로 다른 심볼이있는 가장자리가있는 정사각형/사각형 만들기

여기에

6X9 :

001111100 
011111110 
111111111 
111111111 
011111110 
001111100 

9x6 : (? 콘솔은 바로 0부터 9까지 간다 때문에) 내가 여기까지 왔

001100 
011110 
111111 
111111 
111111 
111111 
111111 
011110 
001100 

ㅁ 두 가지 예 에 코너를 고려하여 추가 할 필요가 있습니까? If 문이 작동합니까 아니면 다른 것이 있습니까? 그리고 네, 이것이 "사각형"만을위한 것이라는 것을 압니다. 두 번째 차원을 어떻게 추가합니까? 도움을받을 수 있을까요?

class Main { 
public static void printSquare(int size) { 
    if(size > 9) { 
     size = 9; 
    } 
    int line = 1; 

     while (line <= size) { 
      int width = size; 
      int i = 1; 

      while (i <= width) { 
       System.out.print("*"); 
       i = i + 1; 
      } 

      System.out.println(); // Newline 
      line = line + 1; 
     } 
    } 
} 

고맙습니다!

+0

이 숙제가 있습니까? – caskey

+0

아니요, 저는 치수에 따라 원 (ish) 테두리가있는 그림을 만들고 싶을 때 코드에서 지정한 그림을 만듭니다. 그것은 최대 및 최소 x 및 y 등으로 제한 될 것입니다! (수많은 문장을 추가해야합니다!) – user2449907

답변

0

세 개의 모서리 기호가 다르다고 간단히 말해야합니다.

Scanner keys = new Scanner(System.in); 

int x = 0; 
int y = 0; 

public void getInput() { 

x = keys.nextInt(); 
y = keys.nextInt(); 
createart(); 

} 

public void createart() { 

System.out.print("00"); 

int counter = 0; 

while (counter < x - 4) { 

System.out.print(1); 

counter++; 

} 
System.out.println("00"); 

counter = 0; 
System.out.print("0"); 
while (counter < x - 2) { 

System.out.print(1); 
counter++; 

} 
System.out.print("0"); 
counter = 0; 
int counter2 = 0; 
while (counter < y - 4) { 
System.out.println(""); 

while (counter2 < x) { 

System.out.print(1); 

counter2++; 
} 
counter++; 
} 
System.out.println(""); 
counter = 0; 
while (counter < x - 2) { 

System.out.print(1); 

counter++; 

} 

counter = 0; 
System.out.println("0"); 
System.out.print("00"); 
while (counter < x - 4) { 

System.out.print(1); 

counter++; 

} 

System.out.print("00"); 

} 

간단한 논리.

+0

와우, 담당자에게 감사드립니다. –