printpyramid.java
来自「单词计算器,可以统计你输入的单词的字母数有多少个等多个程序」· Java 代码 · 共 25 行
JAVA
25 行
import javax.swing.JOptionPane;
public class PrintPyramid
{
public static void main(String[] args)
{
String input=JOptionPane.showInputDialog(null,"Enter the number of lines:",
"Example 3.9 Input",JOptionPane.QUESTION_MESSAGE);
int numberOfLines = Integer.parseInt(input);
if (numberOfLines < 1 || numberOfLines > 15)
{
System.out.println("You must enter a number from 1 to 15");
System.exit(0);
}
for (int row = 1; row <= numberOfLines; row++)
{
for (int column = 1;column <= numberOfLines - row; column++)
System.out.print(" ");
for (int num = row; num >=1 ;num--)
System.out.print((num>=10)?" "+ num : " " + num);
for (int num = 2; num <= row ; num++)
System.out.print((num>=10)? " " + num : " " + num);
System.out.println();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?