java金字塔程序
Pattern programs are used a lot in interviews to understand the logical thinking abilities of the interviewee. Pyramid patterns are very popular and once we get the logic on the way it’s created, writing code to achieve the same is an easy task.
访谈中经常使用模式程序来了解受访者的逻辑思维能力。 金字塔模式非常流行,一旦我们了解了创建方式的逻辑,编写代码即可实现这一目标很容易。
Java中的金字塔模式程序 (Pyramid Pattern Programs in Java)

Here I am providing some examples to create different pyramid patterns from numbers, symbols etc. We will also look into some examples of creating inverted pyramid pattern in java program.
在这里,我提供一些示例来创建与数字,符号等不同的金字塔图案。我们还将研究在Java程序中创建倒金字塔图案的一些示例。
We will try to keep the code simple so that it can be easily understood.
我们将尝试使代码保持简单,以便易于理解。
金字塔的数字模式 (Pyramid Pattern of Numbers)
If you look at the first pattern, every row contains the same number printed the same number of times. However, every row has leading white spaces whose count is “rows-i”. Let’s look at the program to print this pattern.
如果查看第一个模式,则每一行都包含打印相同次数的相同编号。 但是,每一行都有前导空格,其计数为“ rows-i”。 让我们看一下打印此图案的程序。
package com.journaldev.patterns.pyramid;
import java.util.Scanner;
public class PyramidPattern {
private static void printPattern1(int rows) {
// for loop for the rows
for (int i = 1; i <= rows; i++) {
// white spaces in the front of the numbers
int numberOfWhiteSpaces = rows - i;
//print leading white spaces
printString(" ", numberOfWhiteSpaces);
//print numbers
printString(i + " ", i);
//move to next line
System