int n =7; for (int i = 1; i <= n; i++) { for (int m = (n-i); m>=1; m--) { System.out.print(" "); } for (int k = i; k>1; k--) { System.out.print(k); } for (int j = 1; j <=i; j++) { System.out.print(j); } System.out.println(""); }
public static void main(String[] args) { int m =10; for (int i = 1 ; i < m; i++) { int kg = m-i-1; for (int j = 0; j < kg; j++) { System.out.print(" "); }
public void pyramid(int m){
for(int i=0;i<m;i++){
for(int j=0;j<m-1-i;j++){
System.out.print(" ");
}
for(int k=0;k<i*2+1;k++)
System.out.print("*");
System.out.println();
}
}
public static void main(String[] args) {
new Pyramid().pyramid(9);
}}
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("输入层数");
int floors = scan.nextInt();
for (int i = 0; i < floors; i++){
StringBuffer sb = new StringBuffer();
for (int j = 1; j < i + 2; j++){
sb.append("" + j);
}
for (int j = i; j > 0; j--){
sb.append("" + j);
}
System.out.println(sb.toString());
}
}
}
import java.util.*;public class Test01{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("输入层数");
int floors = scan.nextInt();
for (int i = 0; i < floors; i++){
StringBuffer sb = new StringBuffer();
for (int j = i + 1; j > 0; j--){
sb.append("" + j);
}
for (int j = 2; j < i + 2; j++){
sb.append("" + j);
}
System.out.println(sb.toString());
}
}
}
for(int i = 1; i <= n; i++)
{
for(int j = n; j>= 1; j--)
{
if(j > i)
{
System.out.print(" ");
}
else
{
System.out.print(j);
}
}
if(1 != i)
{
for(int s = 2; s <= i; s++)
{
System.out.print(s);
}
}
System.out.println();
}
// TODO Auto-generated method stub
int row = 6;
for(int r=1;r<=row;r++){
for(int n=row;n>=(r+1);n--){
System.out.print(" ");
}
for(int c=1;c<=(2*r-1);c++){
if(c<=r){
System.out.print(c);
}else{
System.out.print(c-r);
}
}
System.out.println("");
}
}
public class OutGoldenTower
{
static int LAYER=9; //金字塔层数, 默认9。
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("输入层数");
int layer = scan.nextInt();
if(layer>1&&layer<21) //小于1或大于20,用默认值9。
{
LAYER=layer;
} int[][] tower=new int[LAYER][LAYER]; //临时数组,实现梯形塔。
int[][] fullTower=new int[LAYER][2*LAYER-1]; //结果数组,尖型金字塔。 //本循环用于实现梯形金字塔结构。
//
for(int i=0;i<tower.length;i++)
{
for(int j=0;j<tower[i].length;j++)
{
if(i>=j)
{
tower[i][j]=j+1;
}
}
}
//本循环用于实现尖型金字塔结构。
//
for(int i=0;i<fullTower.length;i++)
{
System.arraycopy(tower[i],0,fullTower[i],LAYER-1,LAYER); //复制右半部分.
for(int j=0;j<LAYER;j++)
{
fullTower[i][j]=tower[i][LAYER-1-j]; //填充左半部分。
}
} //输出金字塔,考虑到层数为两位数时,对齐问题。
int temp=0;
String out="";
for(int i=0;i<fullTower.length;i++)
{
for(int j=0;j<fullTower[i].length;j++)
{
temp=fullTower[i][j];
if(temp==0) //0用空格代替。
{
out=" ";
if(LAYER>9)
{
out=" "; //层数为两位数时,输出两个空格。
}
} else if(temp<10)
{
out=""+temp; //把一位数字转成字符串。
if(LAYER>9)
{
out=" "+temp; //层数为两位数时,前边补个空格。
}
} else
{
out=""+temp; //层数为两位数时,直接转成字符串输出。
}
System.out.print(out);
}
System.out.println();
}
}
}
// TODO Auto-generated method stub
int row = 9;
for(int r=1;r<=row;r++){
for(int n=row;n>=(r+1);n--){
System.out.print(" ");
}
for(int c=1;c<=(2*r-1);c++){
if(c<=r){
System.out.print(r-(c-1));
}else{
System.out.print((c+1)-r);
}
}
System.out.println("");
} }这个可以实现
// TODO Auto-generated method stub
int row = 9;
for(int r=1;r<=row;r++){
for(int n=row;n>=(r+1);n--){
System.out.print(" ");
}
for(int c=1;c<=(2*r-1);c++){
if(c<=r){
System.out.print(r-(c-1));
}else{
System.out.print((c+1)-r);
}
}
System.out.println("");
} }
int n =7;
for (int i = 1; i <= n; i++) {
for (int m = (n-i); m>=1; m--) {
System.out.print(" ");
}
for (int k = i; k>1; k--) {
System.out.print(k);
}
for (int j = 1; j <=i; j++) {
System.out.print(j);
}
System.out.println("");
}
public static void main(String[] args) {
int m =10;
for (int i = 1 ; i < m; i++) {
int kg = m-i-1;
for (int j = 0; j < kg; j++) {
System.out.print(" ");
}
for (int j = i; j >0; j--) {
System.out.print(j);
}
for (int j = 2; j <= i; j++) {
System.out.print(j);
}
System.out.println();
}
}