Skip to content

Instantly share code, notes, and snippets.

@vemacs
Created February 6, 2017 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vemacs/1521bbc58a6d414eb31337497ec45a07 to your computer and use it in GitHub Desktop.
Save vemacs/1521bbc58a6d414eb31337497ec45a07 to your computer and use it in GitHub Desktop.
/*
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