可以自己来做啊
所在版块:社会百科 发贴时间:2003-06-10 19:47  评分:

用户信息
复制本帖HTML代码
高亮: 今天贴 X 昨天贴 X 前天贴 X 
class test
{
final static int NUM_LEN = 4;
public static void main (String args[]) throws Exception
{
System.out.println(format(2) + format(300) + "\r\n" + format(10) + format(20));
}

static String format(int num) throws Exception
{
String tmp = String.valueOf(num);
int len = tmp.length();
if (len > NUM_LEN)
throw new Exception("Number value out of range");
int diff = NUM_LEN - len;
for (int i=0; i<diff; i++)
tmp = " "+tmp;
return tmp;
}
}
.
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!

Put your OWN COOL signature here!
 相关帖子 我要回复↙ ↗回到正文
问java format的问题 beast   (166 bytes , 490reads )
try java.text.DecimalFormat 想念老乡   (0 bytes , 219reads )
错了 beast   (126 bytes , 231reads )
可以这样处理。。 辰星   (46 bytes , 202reads )
不可以,那样的话就和前一个数字的位数有关 beast   (84 bytes , 168reads )
可以自己来做啊 我心为谁动   (444 bytes , 364reads )
thanks so much for making this method yourself. beast   (59 bytes , 229reads )