Guest User

Untitled

a guest
Jul 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Triangle {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7.  
  8. int level = 0;
  9. if(n % 2 == 0) {
  10. level = n / 2;
  11. int count = 2;
  12. for(int i=0; i<level; i++) {
  13. for(int j=0; j<count; j++) {
  14. System.out.print("*");
  15. }
  16. System.out.println();
  17. count += 2;
  18. }
  19. }
  20. else {
  21. level = n / 2 + 1;
  22. int count = 1;
  23. for(int i=0; i<level; i++) {
  24. for(int j=0; j<count; j++) {
  25. System.out.print("*");
  26. }
  27. System.out.println();
  28. count += 2;
  29. }
  30. }
  31. sc.close();
  32. }
  33. }
Add Comment
Please, Sign In to add comment