直角三角形打印

package test1;

import java.util.Scanner;

public class PrintTriangle {
	void displayTriangle(int height) {
		for (int m = 0; m < height; ++m) {
			for (int n = 0; n < m + 1; ++n) {
				System.out.print('*');
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入一个数:");
		int s = in.nextInt();
		PrintTriangle obj = new PrintTriangle();
		obj.displayTriangle(s);
	}
}

测试:

请输入一个数:
5
*
**
***
****
*****

posted @ 2019-10-27 13:35  宝娟  阅读(127)  评论(0编辑  收藏  举报