Java Do-While

Record·2021년 3월 25일
0

오늘의 개념 정리 [Do-While]

What's do-while?

  • do {실행문;} while (조건문);
  • 반드시 마지막에 ;을 붙여야 함
  • While과 달리, 무조건 한번은 실행
    While = 조건 만족 X → 한번도 반복 X

How to use

import java.util.Scanner;

public class 파일 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 문자 1개 입력
        char 변수1 = sc.next().charAt(0);
        char 변수2 = '문자';
        do {
            System.out.print(변수2 + " "); // print = 한 줄로 출력
            변수2 += 1; // 변수2++;
                       // 변수2 = 변수2 + 1;
        } while (변수2 <= 변수1);
    }
}
profile
👨🏻‍💻 Web Developer

0개의 댓글