本帖最后由 lz895192176 于 2015-9-18 00:11 编辑
import java.util.Scanner;
class For_SJX {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个行数:");
int num = sc.nextInt();
for (int i = 1; i <= num; i++) {
//控制空格数,规律:每一行的空格数 = 总行数 - 当前行数
for (int s = 1; s <= num -i; s++) {
System.out.print(" ");
}
//控制每一行的*数,规律:每一行的*数 = 2*当前行数 -1
for (int x = 1; x <= 2*i -1; x++) {
System.out.print("*");
}
System.out.println();
}
}
}
|
|