ArrayPyramid
public class ArrayPyramid {
public static void main(String[] args) {
// TODO Auto-generated method stub
String palindrome = "Devendra";
int len = palindrome.length();
System.out.println("length :"+len);
char tempCharArray[] = new char[len]; // single dimention
// put original string in an
// array of chars
for (int i = 0; i < len; i++) {
// add values in single dimention..
tempCharArray[i] =
palindrome.charAt(i);
}
char c[][]=new char[len][len]; // two dimention
for (int row = 0; row < len; row++) {
for(int col=0;col<=row;col++) { // same no of cols as row no i.e 1st row has 1 col and 2nd row has 2 cols
// add values in two dimention
c[row][col]=tempCharArray[col];
//System.out.println("c["+(row)+"]["+(col)+"]="+tempCharArray[col]);
System.out.print(""+c[row][col]);
}
System.out.println(" ");
}
}
}
Comments