java知识小计
1.随即生成字母或者数字的方法 .....
???????? public? String getNumandChar(int lenth){
??????????????? String str="";
???????????? //生成随即数的类...
???????????????? Random rs=new Random();
???????????????? for(int i=0;i<lenth;i++){
????????????????????? //生成数字或者字母
???????? ? ? ? ? ? ? ? ? String charOrNum=rs.nextInt(2)%2==0?"char":"num";
?
?????????????? ? ? ? ? ? if("char".equalsIgnoreCase(charOrNum)){
????????????????????????? //生成大写或者小写
????????????????????????? ?? int? upperOrLower=rs.NextInt(2)%2==0?65:97
?????????????????????????? //26个大小写字母
????????????????????? ? ???? str+=(char)(upperOrLower+rs.nextInt(26));
???????????????? ? ? ?? ? }else if("num".equalsIgnoreCase(charOrNum"){
?????????????????????????????? //0-9十个数字
??????????????????????????????? str+=String.valueOf(rs.nextInt(10));
?????????????????????????? }
??????????? return? str;
??????? }
???????????
}
?
?
2:根据今天的日期计算得到明天的日期。
??? public? String getNextDate(){
????????? //new 一个当前的date时间
???????? Date date=new Date();
??????? //new 一个格式化时间的对象
???????? SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd(E)");
?????? //调用下面的方法得到明天的时间
???????? date=nextDay(date,1);
?????? //格式化输出当前时间(例:2011/09/01(四))
????????? String s=sdf.format(date);
????????? return s;
}
?
?????? public Date nextDay(Date date,int offset ){
?????? //得到一个calendar类对象
???????? Calendar cal=Calendar.getInstance();
?????? //set? 当前时间
???????? cal.setTime(date);
??????? //给日历字段该值加1
???????? cal.set(Calendar.DAY_OF_YEAR,Calendar.get(Calendar.DAY_OF_YEAR)+offset);
???????? //返回一个date型时间
????????? return cal;.getTime();
?
?
}
?
?
?
?
?