Java IntStream example - print star patterns

Byul·2023년 6월 13일

Java

목록 보기
6/10
IntStream.range(0, 5).forEach(i -> {
	IntStream.range(-1, i).forEach(j -> System.out.print("*"));
	System.out.println();
});
*
**
***
****
*****	
IntStream.range(0, 5).forEach(i -> {
	IntStream.range(0, 5).forEach(j -> System.out.print(j > i - 1 ? "*" : ""));
	System.out.println();
});
*****
****
***
**
*
IntStream.range(0, 5).forEach(i -> {
	IntStream.range(0, 5).forEach(j -> System.out.print(j < 4 - i ? " " : "*"));
	System.out.println();
});
    *
   **
  ***
 ****
*****
IntStream.range(0, 5).forEach(i -> {
	IntStream.range(0, 5).forEach(j -> System.out.print(j < i ? " " : "*" ));
	System.out.println();
});		
*****
 ****
  ***
   **
    *
profile
junior backend developer

0개의 댓글