RT
------解决方案--------------------------------------------------------
用StringBuffer的append()补0,然后reverse(),可以不?
------解决方案--------------------------------------------------------
- Java code
public String convert(int n){ String s = "" + n; for(int i = s.length();i < 10;i++){ s = '0' + s; } return s;}
------解决方案--------------------------------------------------------
同问有简单的没?
- Java code
import java.util.*;public class test {public static void main(String args[]){ Random rand=new Random(); StringBuilder sb=new StringBuilder(); String x; x=rand.nextInt(999999999)+""; int i=10-x.length(); while(i>0){ sb.append("0"); i--; } sb.append(x); System.out.println(sb.toString());}}
------解决方案--------------------------------------------------------
import java.util.*;
public class compare
{
public static void main(String[]args)
{
S
System.out.println(new compare().getResult());
}
public Integer getLength(){
Random ran = new Random();
int len = ran.nextInt(10);
return len;
}
public String getResult(){
Random ran = new Random();
String returnValue ="";
int len =getLength();
for(int i=1;i<=len;i++){
Integer chara=ran.nextInt(10);
returnValue+=chara.toString();
}
if(len<10)
{
returnValue="0000000000".substring(0,10-len)+returnValue;
}
return returnValue;
}
}
------解决方案--------------------------------------------------------
import java.text.DecimalFormat;
public class Main {
public static void main(String[] args)
{
int i = 3214561;
DecimalFormat df = new DecimalFormat("0000000000");
System.out.println(df.format(i));
}
}
哦。不好意思。开始理解错了意思。原来不是要输出啊。那就用这个吧。。。
------解决方案--------------------------------------------------------
名有特色