Java中如何输出倒的星号

在屏幕上输出:
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

import java.util.Scanner;
public class Test {
 public static void main(String[] args) {
  System.out.println("请输入倒三角形的行数:");
  Scanner sca = new Scanner(System.in);
  int n = sca.nextInt();
  for (int i = n; i >= 1; i--) {
   for (int j = 0; j < n - i; j++) {
    System.out.print(" ");
   }
   for (int k = 0; k < 2 * i - 1; k++) {
    System.out.print("*");
   }
   System.out.println();
  }
 }
}

追问

您用的是什么软件呀

追答

myeclipse

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-07-07
输出倒立的星号,需要先输出整行,然后再进行两层循环,并逐行控制输出的星号数量,形成倒立的阶梯输出。

下面以倒等边三角形为例输出倒的星号,代码为:
public static void main(String[] args) {
int n = 5;
String c = " ";
String x = "*";
for(int j=0;j<2*(n+1)-1;j++){
System.out.print(x);
}
System.out.println();
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2 * n; j++) {
if (j == i+1 || j == (2*n - i-1)) {
System.out.print(x);
} else {
System.out.print(c);
}

}
System.out.println();
}
}
第2个回答  2013-11-13
public class star {

public static void main(String[] args) {
for(int i=9;i>0;i--){
for(int k=0;k<i;k++){
System.out.print("*");
}
System.out.println();
}
}

}本回答被提问者采纳