怎么使用java编写出来等差数列,第一行为1个号*,第二行为3个*,第三行为5个*,第四行为3个*,第五行为*1个*
- 提问者网友:鐵馬踏冰河
- 2021-06-04 00:58
- 五星知识达人网友:杯酒困英雄
- 2021-06-04 02:32
复制别人答案的都去SI!!!!!
最近网络老是有一群不要脸的人!
public class Test {
public static void main(String[] args) {
int a;
int b;
for (a = 1; a <= 3; a++) {
for (b = 1; b <= 3 + a - 1; b++) {
if (b <= 3 - a) {
System.out.print(" ");
} else
System.out.print(" *");
}
System.out.print("\n");
}
for (a = 1; a < 3; a++) {
for (b = 1; b <= 2 * 3 - a - 1; b++) {
if (b <= a) {
System.out.print(" ");
} else
System.out.print(" *");
}
System.out.print("\n");
}
System.out.println();
}
}
- 1楼网友:往事隔山水
- 2021-06-04 05:07
public static void main(String[] args) { int count= 8; int num = 0; int middle =count/2; for(int i=0 ;i<(count+1);i++){ if(i>=middle){ num-=2; }else if(i==0){ num=1; }else{ num+=2; } for(int j=0;j<num;j++){ System.out.print("*"); } System.out.println(""); } }
- 2楼网友:一秋
- 2021-06-04 03:28
public class Test { public static void main(String[] args) { for(int i=1;i<=5;i++)
{ if(i%2!=0) { for(int j=0;j<i;j++) { System.out.print("*"); } System.out.println(); } } for(int i=3;i>=1;i=i-2) { for(int j=0;j<i;j++) System.out.print("*"); System.out.println(); }
}
}
- 3楼网友:一袍清酒付
- 2021-06-04 03:15