Alphabet Triangle
Previous | Home | Next |
Program for the Alphabet Triangle, but just remember that the row shouldn't be exceed to 7.
/*
* Save as a alphabetTriangle.java
* Following program for print alphabet triangle(increament form)
*/
package r4r.co.in;
import java.io.*;
public class alphabetTriangle {
public static void main(String[] args) throws IOException {
BufferedReader Digit = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Row of the Triangle(>7):");
String s1 = Digit.readLine();
//Code for AlphabetTriangle
char ascii[] = new char[100]; //Initilize ascii[]
for (int i = 0, a = 65; a < 99; a++) { //store value in array
ascii[i] = (char) a; //Type conversion
i++; //Increament value in array
}
int n1 = Integer.parseInt(s1); //Type Conversition
System.out.println("Here Triangle:\n");
int count = 0;
for (int i = 0; i < n1; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(ascii[count++]);
}
System.out.print("\n");
}
}
}
Enter the Row of the Triangle(>7):
7
Here Triangle:A
BC
DEF
GHIJ
KLMNO
PQRSTU
VWXYZ[\
Previous | Home | Next |