求一个用java 写的小程序 打印五角星

一时兴起 想试试打印个五角星 是用 "*" 拼出来的哦 嗯 用的是循环
2024-12-02 09:27:05
推荐回答(1个)
回答1:

//第一种用String数组
public static void main(String[] args){
String[] wujiaoxing={" *"," * *","* * * *"," * *"," * *"," * * * *","* *"};
for(int i=0;i System.out.println(wujiaoxing[i]);
}
} /*第二种用char数组
public class Test{
public static void main(String[] args){
char[][] pentagram={
{' ',' ',' ',' ','*','\r'},
{' ',' ',' ','*',' ','*','\r'},
{'*',' ','*',' ',' ',' ','*',' ','*','\r'},
{' ','*',' ',' ',' ',' ',' ','*','\r'},
{' ',' ','*',' ',' ',' ','*','\r'},
{' ','*',' ','*',' ','*',' ','*','\r'},
{'*',' ',' ',' ',' ',' ',' ',' ','*','\r'}
};
for(int i=0;i<7;i++){
for(int j=0;j System.out.print(pentagram[i][j]);
}
}
}
}*/ 或者你看看这个也行 http://blog.csdn.net/bao110908/archive/2007/11/27/1904452.aspx