import java.text.*;
import java.util.*;public class RandomNum {
public String RandomNum () throws Exception {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "HHMMmmddss" );
StringBuffer time = new StringBuffer( simpleDateFormat.format( Calendar.
getInstance().
getTime() ) );
Random rand = new Random();
for ( int i = 0; i < 5; i++ ) {
time.append( rand.nextInt( 9 ) ); //每次生成一位的随机数并加再str后面.这样不用考虑高位为0的情况
}
return time.toString();
}
public void genRandomNum(int count)throws Exception{
for(int i=1;i<=count;i++){
String s = RandomNum();
System.out.println(s);
}
}
public static void main(String[] args)throws Exception{
RandomNum rn = new RandomNum();
rn.genRandomNum(10);
}
}
import java.util.*;public class RandomNum {
public String RandomNum () throws Exception {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "HHMMmmddss" );
StringBuffer time = new StringBuffer( simpleDateFormat.format( Calendar.
getInstance().
getTime() ) );
Random rand = new Random();
for ( int i = 0; i < 5; i++ ) {
time.append( rand.nextInt( 9 ) ); //每次生成一位的随机数并加再str后面.这样不用考虑高位为0的情况
}
return time.toString();
}
public void genRandomNum(int count)throws Exception{
for(int i=1;i<=count;i++){
String s = RandomNum();
System.out.println(s);
}
}
public static void main(String[] args)throws Exception{
RandomNum rn = new RandomNum();
rn.genRandomNum(10);
}
}
解决方案 »
- 怎么整合ssh三大框架
- webservice+axis2入门求救
- 连接数据库报错
- [提问]: jsp里如何直接调用ModelAndView()里传递的参数 ??
- Invocation of init method failed; nested exception is java.lang.NullPointerExcep
- 请教 如何在 Struts 中使用 下载 ?会做的高手指点一下.最好有代码说明一下..谢谢
- jsp中用 SQL server2000要下载jdbc驱动吗???
- 有没有在JSP中调用短信接口的例子
- 只打印页面上的表格~~~
- jdbc and MS SQL server 连接问题
- 50万会员的电影下载、Blog、相册,流媒体不在这个服务器上,这个服务器怎么配置硬件?
- 高分spring 中 ClassPathXmlApplicationContext问题
import java.util.*;public class RandomNum {
public String RandomNum () throws Exception { Random rand = new Random();//提前到这里就好了 SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "HHMMmmddss" );
StringBuffer time = new StringBuffer( simpleDateFormat.format( Calendar.
getInstance().
getTime() ) );
for ( int i = 0; i < 5; i++ ) {
time.append( rand.nextInt( 9 ) ); //每次生成一位的随机数并加再str后面.这样不用考虑高位为0的情况
}
return time.toString();
}
public void genRandomNum(int count)throws Exception{
for(int i=1;i<=count;i++){
String s = RandomNum();
System.out.println(s);
}
}
public static void main(String[] args)throws Exception{
RandomNum rn = new RandomNum();
rn.genRandomNum(10);
}
}