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
/* | |
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