x
xxx
xxxxx
xxxxxxx
package test;
public class Tree {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n =4 ;
for(int i=1;i<=n;i++){
for(int j = n-i;j>0;j--){
System.out.print(" ");
}
for(int k = 0;k<2*i-1;k++){
System.out.print("x");
}
System.out.println();
}
}
}
*
* *
* * *
* * * *
* * *
* *
*
package test;
public class Diamond {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 7;
int m =n/2+1;
for(int i=1;i<=m;i++){
for(int j=m-i;j>0;j--){
System.out.print(" ");
}
for(int k =0;k<2*i-1;k++){
if(k%2 ==1){
System.out.print(" ");
}else{
System.out.print("*");
}
}
System.out.println();
}
for(int i=m+1;i<=n;i++){
for(int j = i-m;j>0;j--){
System.out.print(" ");
}
for(int k = 0;k<2*m-1-2*(i-m);k++){
if(k%2 ==1){
System.out.print(" ");
}else{
System.out.print("*");
}
}
System.out.println();
}
}
}