Created
February 6, 2017 01:37
-
-
Save vemacs/1521bbc58a6d414eb31337497ec45a07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
Enter height of triangle: 10 | |
* | |
** | |
*** | |
**** | |
***** | |
****** | |
******* | |
******** | |
********* | |
********** | |
********* | |
******** | |
******* | |
****** | |
***** | |
**** | |
*** | |
** | |
* | |
*/ | |
import java.util.Optional; | |
import java.util.Scanner; | |
import java.util.function.*; | |
import java.util.stream.IntStream; | |
public class Triangle { | |
private static IntFunction<IntConsumer> f = (m) -> ((IntConsumer) (i) -> IntStream.range(0, i) | |
.forEach((n) -> System.out.print("*"))) | |
.andThen((n) -> System.out.println()) | |
.andThen((n) -> Optional.ofNullable(n < m ? n : null) | |
.ifPresent((el) -> Triangle.f.apply(m) | |
.andThen((l) -> Triangle.f.apply(0) | |
.accept(n)).accept(n + 1))); | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("Enter height of triangle: "); | |
f.apply(scanner.nextInt()).accept(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment