-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week1][입문편] 2강 코틀린에서 반복문을 다루는 방법 (#5)
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |