본문 바로가기
프로그램/Java 1000제

Java 4제] 1~10까지 출력하기(반복문 사용)

by 건티 2022. 11. 7.
728x90

출처 : 반크_독도의 날

 

참고풀이]

public class OneAndTen {

 

   public static void main(String[] args) {

      // TODO Auto-generated method stub

      int i;

 

      System.out.printf("[1~10까지 출력하기]\n");

      System.out.printf("▶ while 반복문\n");

      i=0;

      while(i++<10)

         System.out.printf("%3d",i);

 

      System.out.printf("\n▶ do~while 반복문\n");

      i=1;

      do {

         System.out.printf("%3d",i);

      }while(++i<=10);

 

      System.out.printf("\n▶for 반복문\n");

      for(i=1;i<=10;i++)

         System.out.printf("%3d",i);

 

      System.out.printf("\n▶ 무한Loop\n");

      i=0;

      while(true)

      {

         if(++i>10) break;

         System.out.printf("%3d",i);

      }

   }

 

}

 

 

참고풀이 결과]

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 가을

 

반응형

댓글