- /*import java.util.Scanner;
- 打印出如下格式的三角形:
- * * * * *
- * * * *
- * * *
- * *
- *
- */
- public class ForDemo {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.print("请输入三角形的行数: ");
- int index = input.nextInt();
- for (int x = 1; x <= index; x ++){
- //首先打印出*前面的空格
- for (int y = 1; y < x; y++)
- System.out.print(" ");
- //再打印出*
- for (int y = x; y <= index; y++)
- System.out.print("* ");
- System.out.println();
- }
- }
- }
复制代码 |
|