Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //詢問第三種for迴圈語法.java
- import static java.lang.System.out;
- import java.util.stream.IntStream;
- public class MainClass {
- public static void main(String[] args) {
- char[] array = {'*', '*', '*', '*', '*', '*', '*', '*', '*', '*'};
- //第一種傳統for迴圈寫法
- for (int i = 0; i < array.length; i++) {
- out.printf("%c", array[i]);
- }
- out.printf("\n");
- /第二種加強型foreach迴圈寫法
- for (char c : array) {
- out.printf("%c", c);
- }
- out.printf("\n");
- //第三種for迴圈寫法
- for (int i = 0; i < 5; i++) {
- IntStream.range(0, i).forEach(c -> System.out.print("*"));
- }
- out.printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement