Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String linea = "";
- Scanner sc = new Scanner(System.in);
- int num;
- System.out.println("¿De cuántos pisos quiere realizar el triangulo?");
- num = sc.nextInt();
- if (num > 0) {
- System.out.print(".");
- for (int i = num; i > 0; i--) {
- for (int espacio = 1; espacio <= (num - i); espacio++) {
- linea = "." + linea;
- }
- String estrella1 = "", estrella2 = "";
- if (i % 2 == 0) {
- estrella1 = "*.";
- estrella2 = "*.";
- }
- else {
- estrella1 = "*.";
- estrella2 = "*.";
- }
- for (int j = 1; j <= i; j++) {
- if (j % 2 == 0) {
- linea = linea + estrella2;
- } else {
- linea = linea + estrella1;
- }
- }
- System.out.println(linea);
- linea = ".";
- }
- }
- else {
- System.out.println(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement