close
ex:輸入3
print:
******
** **
* *
* *
ex:輸入4
print:
********
*** ***
** **
** **
* *
的程式...
好感動,終於寫出來了~(檔名:test1)
import java.util.*;
public class test1
{
public static void main(String[] args)
{
int star1, star2, aNew, space;
System.out.println("請輸入一個數");
Scanner x = new Scanner(System.in);
aNew = x.nextInt();
for (star1 = aNew; star1 >= 0; star1--)
{
for (star2 = 1; star2 <= star1; star2++)
{
System.out.print("*");
}
for (space = aNew; space >= star2; space--)
{
System.out.print(" ");
}
for (star2 = 1; star2 <= star1; star2++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
全站熱搜
留言列表