从键盘录入一个整数并打印出倒三角星阵;
package co.itheima.cn;
import java.util.Scanner;
public class Demo2_Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个整数");
String a = sc.nextLine();
try {
getXing(a);
} catch (Exception e) {
System.out.println("您输入的不是整数,请重新输入");
;
} finally {
}
}
public static void getXing(String m) {
for (int i = Integer.parseInt(m); i >= 0; i--) {
for (int j = 1; j <= i; j++) {
System.out.print("*" + " ");
}
System.out.println();
}
}
}
{:2_30:}
|
|