-
[자바기초] PART2 구구단 6, 7단 구현 - 반복문카테고리 없음 2022. 9. 5. 20:59
- while 반복문을 사용한다.
public class Gugudan {
public static void main(String[] args) {
int i = 1;
while (i < 10) {
System.out.println(6 * i);
i = i + 1;
}
}
}- for 반복문을 사용한다.
public class Gugudan {
public static void main(String[] args) {
for(int i = 1; i < 10; i++) {
System.out.println(7 * i);
}
}
}반복되는 구간은 최대한 간결하게 코드를 작성하는 것이 좋기에 반복문(while, for)을 사용한다.
(반복적인 작업을 변수와 반복문을 활용해 제거)
while보다 for 반복문이 더욱 간결하게 사용가능하다.