📄 main.java
字号:
/*
* Main.java
*
* Created on 2007年8月10日, 下午12:54
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package javaapplication6;
import javax.swing.JOptionPane;
/**
*
* @author xue hao
*/
public class Main {
/** Creates a new instance of Main */
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// Prompt the user to enter the size of the side of a square
String input = JOptionPane.showInputDialog("Enter length of side: ");
// Convert string to int value
int length = Integer.parseInt(input);
if (length > 20)
{
JOptionPane.showMessageDialog(null, "The length must between 1 and 20!");
System.exit(0);
}
// Display heading
String output = "Enter length of side : " + length + "\n";
// Display the first line
for (int line = 1; line <= length; line++)
{
output += "* ";
}
// Display the row
output += "\n";
for (int row = 1; row <= (length - 2); row++)
{
output += "*";
for (int line = 1; line <= (length - 2); line++)
{
output += " ";
}
output += "*" + "\n";
}
// Display the last line
for (int line = 1; line <= length; line++)
{
output += "* ";
}
// Display the output
JOptionPane.showMessageDialog(null, output);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -