package chapter4;
import javax.swing.JOptionPane;public class PrintPyramid { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String input = JOptionPane.showInputDialog("Enter the number of lines:");
int numberOfLines = Integer.parseInt(input);
String output = "";
for (int row = 1; row <= numberOfLines; row++){
for (int w = numberOfLines; w > row; w-- ){
output += " ";
for (int i = w ; i != 0; i = i / 10 ){
output += " ";
}
}
for(int w = row ; w >= 1; w--)
output += " " + w;
for(int w = 2 ; w <= row ; w++)
output += " " + w;
for (int w = numberOfLines ; w > row; w--){
output += " ";
for (int i = w ; i != 0; i = i / 10 ){
output += " ";
}
}
output += " \n";
}
//JOptionPane.showMessageDialog(null, output);
System.out.print(output);
}}
import javax.swing.JOptionPane;public class PrintPyramid { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String input = JOptionPane.showInputDialog("Enter the number of lines:");
int numberOfLines = Integer.parseInt(input);
String output = "";
for (int row = 1; row <= numberOfLines; row++){
for (int w = numberOfLines; w > row; w-- ){
output += " ";
for (int i = w ; i != 0; i = i / 10 ){
output += " ";
}
}
for(int w = row ; w >= 1; w--)
output += " " + w;
for(int w = 2 ; w <= row ; w++)
output += " " + w;
for (int w = numberOfLines ; w > row; w--){
output += " ";
for (int i = w ; i != 0; i = i / 10 ){
output += " ";
}
}
output += " \n";
}
//JOptionPane.showMessageDialog(null, output);
System.out.print(output);
}}
才学java最好不要用eclipse之类的开发工具,用普通的文本编辑器慢慢打才能更好的锻炼编程能力
其实这样会影响你的很多基础东西···
搞专业点,稳点···