Print alphabet triangle Using Java
Previous | Home | Next |
Print alphabet triangle Using Java
//Following program for print alphabet triangle
package r4r.co.in;
import java.io.*;
public class NewClass {
public static void main(String[] args) throws IOException {
BufferedReader Digit = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Row:");
String s1 = Digit.readLine();
//Code for Triangle
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[i]);
}
System.out.print("\n");
}
}
}
Enter the Row:
8
Here Triangle:A
BB
CCC
DDDD
EEEEE
FFFFFF
GGGGGGG
HHHHHHHH
Previous | Home | Next |