Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1.  
  2. String linea = "";
  3. Scanner sc = new Scanner(System.in);
  4. int num;
  5.  
  6. System.out.println("¿De cuántos pisos quiere realizar el triangulo?");
  7. num = sc.nextInt();
  8. if (num > 0) {
  9. System.out.print(".");
  10. for (int i = num; i > 0; i--) {
  11. for (int espacio = 1; espacio <= (num - i); espacio++) {
  12. linea = "." + linea;
  13. }
  14.  
  15. String estrella1 = "", estrella2 = "";
  16. if (i % 2 == 0) {
  17. estrella1 = "*.";
  18. estrella2 = "*.";
  19. }
  20.  
  21. else {
  22. estrella1 = "*.";
  23. estrella2 = "*.";
  24. }
  25. for (int j = 1; j <= i; j++) {
  26. if (j % 2 == 0) {
  27. linea = linea + estrella2;
  28. } else {
  29. linea = linea + estrella1;
  30. }
  31.  
  32. }
  33. System.out.println(linea);
  34. linea = ".";
  35. }
  36. }
  37.  
  38. else {
  39. System.out.println(" ");
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement