fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int n = 3;
  13. for (int layer = 1;layer <= n; layer ++) {
  14. for (int base = 0;base < layer;base ++) {
  15. printbase(n);
  16. }
  17. System.out.print("\n");
  18. }
  19. }
  20. public static void printbase(int n) {
  21. for(int base = 1;base <= n;base ++) {
  22. for (int star = 0;star < base;star ++) {
  23. System.out.print("*");
  24. }
  25. for (int space = 0;space < n - base;space ++) {
  26. System.out.print(" ");
  27. }
  28. System.out.print("\n");
  29. }
  30. }
  31. }
Success #stdin #stdout 0.09s 52616KB
stdin
Standard input is empty
stdout
*  
** 
***

*  
** 
***
*  
** 
***

*  
** 
***
*  
** 
***
*  
** 
***