用Java for循环编写如下 * * * * *
展开全部
for(int i = 1; i<=9; i++)
{
String line = "";
for(int j = 1; j <=9; j++)
{
if( (i <= 5 && (i + j == 6 || j - i == 4)) //前5行
||(i > 5 && (i - j == 4 || i + j == 14))) //后4行
line += "*"
else
line += " "
}
System.out.println(line);
}
{
String line = "";
for(int j = 1; j <=9; j++)
{
if( (i <= 5 && (i + j == 6 || j - i == 4)) //前5行
||(i > 5 && (i - j == 4 || i + j == 14))) //后4行
line += "*"
else
line += " "
}
System.out.println(line);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class test {
public static void main(String[] args) {
int hangshu = 9;
int yiban = hangshu / 2 + 1;
int yibanduo = hangshu / 2;
for(int k = 1;k <= yiban;k++){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
for(int k = yibanduo;k >=1;k--){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
}
}
public static void main(String[] args) {
int hangshu = 9;
int yiban = hangshu / 2 + 1;
int yibanduo = hangshu / 2;
for(int k = 1;k <= yiban;k++){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
for(int k = yibanduo;k >=1;k--){
for(int i = 1;i <= (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i <= ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询