Created
November 11, 2019 22:45
-
-
Save shgonzalez/0b18931de20a7a7557b8b586a6058bfe to your computer and use it in GitHub Desktop.
How to program in Java 8 Deitel & Deitel exercise triangule with stars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Ejercicio 5.15 | |
public class Triangulos { | |
public static void main (String[] a) { | |
//a | |
for ( int i = 1 ; i <= 10; i++ ) { | |
for ( int z=1; z<=i; z++) { | |
System.out.print("*"); | |
} | |
System.out.println(); | |
} | |
System.out.println(); | |
//b | |
for ( int i = 10 ; i >= 1; i-- ) { | |
for ( int z=i; z>=1; z-- ) { | |
System.out.print("*"); | |
} | |
System.out.println(); | |
} | |
System.out.println(); | |
//c | |
String msg = "***********"; | |
for ( int i = 10 ; i >= 1; i-- ) { | |
String newMsg = msg.substring(0, i); | |
System.out.printf("%10s", newMsg); | |
System.out.println(); | |
} | |
System.out.println(); | |
//d | |
for ( int i = 1 ; i <= 10; i++ ) { | |
String newMsg = msg.substring(0, i); | |
System.out.printf("%10s", newMsg); | |
System.out.println(); | |
} | |
/* | |
System.out.printf("%10s%n","**********"); | |
System.out.printf("%10s%n","*********"); | |
System.out.printf("%10s%n","********"); | |
System.out.printf("%10s%n","*******"); | |
System.out.printf("%10s%n","******"); | |
System.out.printf("%10s%n","*****"); | |
System.out.printf("%10s%n","****"); | |
System.out.printf("%10s%n","***"); | |
System.out.printf("%10s%n","**"); | |
System.out.printf("%10s%n","*"); | |
*/ | |
System.out.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment