fork download
  1. import java.nio.CharBuffer;
  2.  
  3. class Main {
  4.  
  5. private static void starLine(int k) {
  6. System.out.println(CharBuffer.allocate(k).toString().replaceAll("\0", "*"));
  7. }
  8.  
  9. public static void stars(int k, int n) {
  10. if (k > n) {
  11. throw new RuntimeException("Cannot do this");
  12. } else if (k == n) {
  13. starLine(k);
  14. } else {
  15. starLine(k);
  16. stars(k + 1, n);
  17. starLine(k);
  18. }
  19. }
  20.  
  21. public static void main(String[] args) {
  22. stars(3, 7);
  23. }
  24. }
  25.  
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
***
****
*****
******
*******
******
*****
****
***