printf格式输出数字,位数不够前面补0,适用与输出编号 printf格式输出:%[flags][width][.perc][F|N|h|l]type 用到了flags中的 0 (注意是零不是欧) ,其百科描述为:将输出的前面补上0,直到占满指定列宽为止(不可以搭配使用-) width 即表示需要输出的位数. int a = 4; printf("%03d",a); 输出:004 也可以用 * 代替位数,在后面的参数列表中用变量控制输出位数: int a = 4; int n = 3
总结:请告诉我更好的方法~~~总觉得不好. package com.badu; import java.util.Scanner; //逆序输出数字: // class fa { public static void main(String[] args) { Scanner c = new Scanner(System.in); System.out.println("请输入数字----"); int a = c.nextInt(); // int b; int d = 0; Sys
使用Python输出一个数字金字塔 运行结果: 源代码: ''' Python输出数字金字塔 ''' for x in range(1,10): print(' '*(15-x),end='') n=x while n>=1: print(n,sep='',end='') n-=1 n+=2 while n<=x: print(n,sep='',end='') n+=1 print()