Java 반복문

218.153.224.21 (토론)님의 2021년 9월 4일 (토) 15:10 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

개요[ | ]

반복문으로는 while문과 for 문이 있다
  • While 문 예제
public class helloj {
    public static void main(String[] args){
        int i = 0;
        while (i < 5) {
            System.out.println(i);
            i++;
        }
    }
}
public class helloj {
    public static void main(String[] args){
        int i = 0;
        do {
            System.out.println(i);
            i++;
        }
        while (i < 5);
    }
}


  • for 문 예제
public class helloj {
    public static void main(String[] args){
        for (int i = 0; i < 5; i++) {
            System.out.println(i);
        }
    }
}
public class helloj {
    public static void main(String[] args){
        String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
        for (String i : cars) {
            System.out.println(i);
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}