"Java 반복문"의 두 판 사이의 차이

(새 문서: ==개요== ; 반복문으로는 while문과 for 문이 있다 *While 문 예제 <syntaxhighlight lang='java' run> public class helloj { public static void main(String[] args){...)
 
 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
39번째 줄: 39번째 줄:
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='java' run>
<syntaxhighlight lang='java' run>
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
public class helloj {
for (String i : cars) {
    public static void main(String[] args){
  System.out.println(i);
        String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
        for (String i : cars) {
            System.out.println(i);
        }
    }
}
}
</syntaxhighlight>
</syntaxhighlight>


[[분류: java  ]]
[[분류: java  ]]

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 }}