- public class GiveYouStars {
- private int row;
- public void rowIn() {
- Scanner sc = new Scanner(System.in);
- while (true) {
- System.out.print("请输入大于0的整数:");
- row = sc.nextInt();
- if (row < 1) {
- System.out.print("输入有误请重新输入。");
- } else {
- break;
- }
- }
- }
- public void show() {
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < row - i - 1; j++) {
- System.out.print(" ");
- }
- for (int j = 0; j < i * 2 + 1; j++) {
- System.out.print("*");
- }
- System.out.println();
- }
- }
- }
复制代码 |
|