编写java程序打印五角星?(用到循环语句)

2024-12-17 10:03:25
推荐回答(1个)
回答1:

第一种用String数组
public class Test{
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]);
}
}
}
}