Alphabet Triangle MethodThere are three methods to print the alphabets in a triangle or in a pyramid form.
Logic:
Using range() functionThis range function stores values in an array from A to Z. here, we use two for loops. Example: Output: Using chr() functionHere the chr() function returns the value of the ASCII code. The ASCII value of A, B, C, D, E is 65, 66, 67, 68, 69 respectively. Here, also we use two for loops. Example: Output: Using range() function with foreachIn this methods we use foreach loop with range() function. The range() function contain values in an array and returns it with $char variable. The for loop is used to print the output. Example: Output: Next TopicAlphabet Triangle Pattern |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India