캬캬백곰 2012. 4. 25. 14:54
728x90

 

 

결과)

1    1    1    1

1    1    1

1    1

1

과 같은 결과값을 만들어내는 프로그램을 이중 for문으로 만들어낼 수 있다.

 public static void main(String[] args) {
  //
  
  for(int i=0; i<4; i++){
   for(int j=i; j<4; j++){
    System.out.print("1"+"\t");
   }
   System.out.println();
  }
  
  System.out.println(); // 한 줄 내리기
  
  for(int i=4; i>0; i--){
   for(int j=1; j<=i; j++){
    System.out.print(1+"\t");
   }
   System.out.println();
  }

두 가지 모두 같은 결과값을 출력한다.

728x90
반응형