问题描述
121232123打入數字,如何會出這整齊三角形
解决方案
本帖最后由 wai2008 于 2010-12-12 11:44:57 编辑
解决方案二:
输入什么数字?几行?几列?还是这样..system.out.println(1);system.out.println(212);system.out.println(32123);
解决方案三:
打入行數,但數字要整齊,可否解決?importjavax.swing.JOptionPane;publicclassprintpyramid{publicstaticvoidmain(String[]args){Stringinput=JOptionPane.showInputDialog("Enterthenumberoflines:");intnumberOfLines=Integer.parseInt(input);if(numberOfLines<1||numberOfLines>15){System.out.println("Youmustenteranumberfrom1to15");System.exit(0);}for(introw=1;row<=numberOfLines;row++){for(intcolumn=1;column<=numberOfLines-row;column++)System.out.print("");for(intnum=row;num>=1;num--){System.out.print((num>=10)?""+num:""+num);}for(intnum=2;num<=row;num++){System.out.print((num>=10)?""+num:""+num);}System.out.println("");}}}
解决方案四:
importjavax.swing.JOptionPane;publicclassprintpyramid{publicstaticvoidmain(String[]args){Stringinput=JOptionPane.showInputDialog("Enterthenumberoflines:");intnumberOfLines=Integer.parseInt(input);if(numberOfLines<1||numberOfLines>15){System.out.println("Youmustenteranumberfrom1to15");System.exit(0);}for(introw=1;row<=numberOfLines;row++){for(intcolumn=1;column<=numberOfLines-row;column++)System.out.print("");for(intnum=row;num>=1;num--){System.out.print((num>=10)?""+num:""+num);}for(intnum=2;num<=row;num++){System.out.print((num>=10)?""+num:""+num);}System.out.println("");}}}