該成死的就不夠靈活了。如果你這樣做,就可以解決問題了
import java.io.*;
public class print
{
public static void main(String [] agrs)
{
int rows=0;
System.out.println("Enter a number:");
try
{
String s="";
BufferedReader in=new BufferedReader (new InputStreamReader(System.in));
s=in.readLine();
rows=Integer.parseInt(s);
}catch (Exception e){};
for(int i=0;i
{
System.out.println();
for(int j=0;j<=2*(rows-1);j++)
{
if(j<=rows-1-i||j>=rows-1+i)
System.out.print(" ");
else
System.out.print("*");
}
}
}
}