Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

package csdncom.tt;

import java.util.Scanner;

/** * Created by Java java.java.java on 2021/10/30. */
public class Sum {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Please enter an integer between 1 and 9");
		int n = sc.nextInt();
		while (n < 1 || n > 9) {
			System.out.println("The number you entered is not between 0 and 9, or is not an integer, please re-enter.");
			n = sc.nextInt();
		}
		for (int i = 1; i <= n; i++) {
			for (int j = n - i; j > 0; j--) {
				System.out.print("");
			}
			for (int j = (i + i - 1); j > 0; j--) {
				System.out.print("*"); } System.out.println(); }}}Copy the code

Print: