主题:求助一到程序题
我要打印出这样的图象
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
我写的程序是这样的的
import javax.swing.JOptionPane;
public class tuan {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int row=1;row<=8;row++){
for(int i=1;i<=(8-row)*3;i++)
System.out.print(" ");
for(int j=1;j<=row*3;j++){
int num=(int)Math.pow(2,j-1);
System.out.printf("%3d",num);
}
for(int k=1;k<=row-1;k++){
int m=(int)Math.pow(2,row-k-1);
System.out.printf("%3d",m);
}
System.out.println();
}
}
}
可是运行结果不对.
1
1 2 1
1 2 4 2 1
1 2 4 8 4 2 1
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
1 2 4 8 16 32 64 32 16 8 4 2 1
1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
我写的程序是这样的的
import javax.swing.JOptionPane;
public class tuan {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for(int row=1;row<=8;row++){
for(int i=1;i<=(8-row)*3;i++)
System.out.print(" ");
for(int j=1;j<=row*3;j++){
int num=(int)Math.pow(2,j-1);
System.out.printf("%3d",num);
}
for(int k=1;k<=row-1;k++){
int m=(int)Math.pow(2,row-k-1);
System.out.printf("%3d",m);
}
System.out.println();
}
}
}
可是运行结果不对.