c:
#include<stdio.h>
int main(){
int a;
while(scanf("%d",&a)!=EOF){
for(int i=0;i<a+1;i++){
for(int j=0;j<a+1-i;j++){
printf("* ");
}
for(int j=0;j<i;j++){
printf(" ");
}
printf("\n");
}
for(int i=0;i<a;i++){
for(int j=-1;j<=i;j++){
printf("* ");
}
for(int j=0;j<a;j++){
printf(" ");
}
printf("\n");
}
}
}
//补成一个虚拟的矩形
c++:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
while(cin>>a){
for(int i=0;i<a+1;i++){
for(int j=0;j<a+1-i;j++){
cout<<"* ";
}
for(int j=0;j<i;j++){
cout<<" ";
}
cout<<endl;
}
for(int i=0;i<a;i++){
for(int j=-1;j<=i;j++){
cout<<"* ";
}
for(int j=1;j<a-i;j++){
cout<<" ";
}
cout<<endl;
}
}
}
Java:
import java.io.*;
public class Main{
public static void main(String[]args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s;
while((s=br.readLine())!=null){
int a=Integer.parseInt(s);
for(int i=0;i<a+1;i++){
for(int j=0;j<a+1-i;j++){
System.out.printf("* ");
}
for(int j=0;j<i;j++){
System.out.printf(" ");
}
System.out.printf("\n");
}
for(int i=0;i<a;i++){
for(int j=-1;j<=i;j++){
System.out.printf("* ");
}
for(int j=1;j<a-i;j++){
System.out.printf(" ");
}
System.out.printf("\n");
}
}
}
}