Project/JAVA

자바 알파벳 피라미드 만들기

아폴로딸기맛 2011. 4. 4. 19:20
알파벳으로 피라미드 탑을 쌓아보자.
public class pyramid{
 public static void main(String[] args){
  
  int cnt = 7;
  int alp = 65;
  for (int i = 1; i<=7 ;i++ ){
   for (int j = 0; j<cnt ;j++ )
   {
    System.out.print("  ");
   } 
   for (int k=0; k< i; k++ ){    
    System.out.printf("%c   ",alp++);
   }System.out.println("");
   cnt--;
  }
  System.out.println("");
 }
}

실행결과는 아래와같다.
Z 뒤에 아스키코드 다음값인 특수문자게 나오게 되었다. 이건 없애야하는건가 모르겠넹,