用java中的for循环语句排列下面的*号 * *** ***** ******* ***** *** * 这是我们的作业,急求啊
展开全部
public class test {
public static void main (String args[]) {
for (int i=1; i<6; i++) {
if(i<4){
for (int j=1; j<=-2*i+9; j++)
System.out.print(" ");
for (int j=1; j<=2*i-1; j++)
System.out.print("* ");
System.out.println();
}
else{
for(int j= 1;j<=2*i-3;j++)
System.out.print(" ");
for(int j=1;j<=-2*i+11;j++)
System.out.print("* ");
System.out.println();
}
}
}
} 这事我写的 不知道符合吗
public static void main (String args[]) {
for (int i=1; i<6; i++) {
if(i<4){
for (int j=1; j<=-2*i+9; j++)
System.out.print(" ");
for (int j=1; j<=2*i-1; j++)
System.out.print("* ");
System.out.println();
}
else{
for(int j= 1;j<=2*i-3;j++)
System.out.print(" ");
for(int j=1;j<=-2*i+11;j++)
System.out.print("* ");
System.out.println();
}
}
}
} 这事我写的 不知道符合吗
展开全部
public class PrintTest {
public static void main(String[] args) {
int n = 7;
for (int i = 1; i <= n; i++) {
if (i <= (n + 1) / 2) {
for (int k = 1; k <= i * 2 - 1; k++)
System.out.print("*");
System.out.println();
} else {
for (int k = 1; k <= (n - i + 1) * 2 - 1; k++)
System.out.print("*");
System.out.println();
}
}
}
}
public static void main(String[] args) {
int n = 7;
for (int i = 1; i <= n; i++) {
if (i <= (n + 1) / 2) {
for (int k = 1; k <= i * 2 - 1; k++)
System.out.print("*");
System.out.println();
} else {
for (int k = 1; k <= (n - i + 1) * 2 - 1; k++)
System.out.print("*");
System.out.println();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int line = 7, semi = line / 2;
for (int i = 0, k = line * line; i < k; i++) {
int row = i / line;
int col = i % line;
if (col == 0 && i > 0) {
System.out.println();
}
System.out.print(Math.abs(semi - col) > semi - Math.abs(semi - row) ? ' ' : '*');
}
for (int i = 0, k = line * line; i < k; i++) {
int row = i / line;
int col = i % line;
if (col == 0 && i > 0) {
System.out.println();
}
System.out.print(Math.abs(semi - col) > semi - Math.abs(semi - row) ? ' ' : '*');
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public static void main(String[] args) {
for (int j = 1; j <= 10; j++)
{
for (int z = 1; z <= 10 - j; z++)
{
System.out.print(
for (int j = 1; j <= 10; j++)
{
for (int z = 1; z <= 10 - j; z++)
{
System.out.print(
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |