java生成随机数字和字母组合
注:1.方法的参数 length 是生成的随机数的长度。
2. 只想要大写的字母 可以使 int choice =65; 只想要小写的字母,就 int choice =97;
import java.util.Random;
public String getCharAndNumr(int length)
{
String val = "";
Random random = new Random();
for(int i = 0; i < length; i++)
{
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
if("char".equalsIgnoreCase(charOrNum)) // 字符串
{
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; //取得大写字母还是小写字母
val += (char) (choice + random.nextInt(26));
}
else if("num".equalsIgnoreCase(charOrNum)) // 数字
{
val += String.valueOf(random.nextInt(10));
}
}
return val;
}
相关文档:
最近要在一个JAVA工程中调用一个别人的DLL库,出现了以下问题:平台是JDK1.6.0_2
别人的DLL导出的函数类似于_Java_Sth_1Find@12 ,而我访问该函数的类如果在default package下就可以正常访问,就是说DLL导出的JNI是在默认包下的,而如果把该类放入特定的包下就会出现Exception in thread "main" java.lang.UnsatisfiedLink ......
System.currentTimeMillis():可以提取到当前时间的毫秒数,产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数。
常见作用:一般都是用2个时间的差值来得到运行时间的,常用来比较2个算法的效率!
long start = System.currentTimeMillis();
// 这里可以加上你要知道的方法运行的时间!!
......
package com.lovo.cq.shopping10_1.common;
import java.sql.*;
public class DbUtil {
private PreparedStatement pstmt = null;
private Connection con = null;
public DbUtil() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://l ......
1.你需要精通面向对象分析与设计(OOA/OOD)、涉及模式(GOF,J2EEDP)以及综合模式。你应该十分了解UML,尤其是class,object,interaction以及statediagrams。
2.你需要学习JAVA语言的基础知识以及它的核心类库
(collections,serialization,streams,networking,
multithreading,reflection,event,h ......