Skip to content

Commit

Permalink
[Week1][입문편] 2강 코틀린에서 반복문을 다루는 방법 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjsmk0902 committed Jun 26, 2024
1 parent 77aa51a commit 83405ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 양승민/입문/src/lec06/lec06Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package lec06;

import java.util.Arrays;
import java.util.List;

public class lec06Main {
public static void main(String[] args) {
// 1. for each 문
List<Long> numbers = Arrays.asList(1L, 2L, 3L);
for (long number : numbers) {
System.out.println(number);
}

// 2. 전통적인 for 문
for (int i = 1; i <= 3; i++) {
System.out.println(i);
}
for (int i = 3; i >= 1; i--) {
System.out.println(i);
}
for (int i = 1; i <= 5; i += 2) {
System.out.println(i);
}

}
}
22 changes: 22 additions & 0 deletions 양승민/입문/src/lec06/lec06Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lec06

fun main() {

// 1. for each 문
val numbers = listOf(1L, 2L, 3L)
for (number in numbers) {
println(number)
}

// 2. 전통적인 for 문
for (i in 1..3) {
println(i)
}
for (i in 3 downTo 1) {
println(i)
}
for (i in 1..5 step 2) {
println(i)
}

}

0 comments on commit 83405ce

Please sign in to comment.