黑马程序员技术交流社区

标题: 将数字转换为字符串,长度不够前面补 [打印本页]

作者: 彭小康    时间: 2012-12-14 11:38
标题: 将数字转换为字符串,长度不够前面补
package test;
import java.util.Scanner;
/**
* java数字转换为字符串,长度不够前面补0
* @author Administrator
*
*/
public class test4 {
private static final String FORMAT = “0000000000″;
/**
* @param args
*/
public static void main(String[] args) {
test4 t = new test4();
System.out.println(t.haoAddOne(FORMAT));
}
public static String haoAddOne(String liuShuiHao){
Integer intHao = Integer.parseInt(liuShuiHao);
intHao++;
Scanner input = new Scanner(System.in);
String strHao = intHao.toString();
System.out.println(“请输入数字:”);
strHao = input.next();
while (strHao.length() < liuShuiHao.length())
strHao = “0″ + strHao;
return strHao;
}
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2