public class Work08 {
public static void main(String[] args) {
String randomCode = getRandomCode();
System.out.println(randomCode);
}
public static String getRandomCode(){
StringBuilder sb = new StringBuilder();
for (char ch = 'a'; ch < 'z'; ch++) {
sb.append(ch);
}
for (char ch= 'A'; ch <= 'C'; ch++) {
sb.append(ch);
}
for (char ch = '0'; ch <= '9'; ch++) {
sb.append(ch);
}
Random r = new Random();
String code = "";
for (int i = 0; i < 4 ; i++) {
int j = r.nextInt(sb.length());
code+= sb.charAt(j);
}
return code;
}
}public class Work07 { public static void main(String[] args) {
String str = "Java语言是面向对象的,Java语言是健壮的,Java语言是安全的,Java是高性能的,Java语言是跨平台的";
String tar = "Java";
System.out.println(search(str,tar));
}
public static int search(String str,String tar){
/* int length = str.length();
System.out.println(length);
//int index = -1;
int i = str.indexOf(tar);
System.out.println(i);*/
//while ((index = str.indexOf(tar)) != -1)
int count = 0;
while(str.indexOf(tar)!=-1){
count++;
str = str.substring(str.indexOf(tar)+tar.length());
}
return count;
}
}public class Work05 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入身份证号码");
String line = sc.nextLine();
boolean check = check(line);
System.out.println(check);
}
public static boolean check(String id) {
//判断长度不是18位不合法
if (id.length() != 18) {
return false;
}
//判断首位是数字零不合法
if (id.charAt(0) == 0) {
return false;
}
//遍历身份证号
for (int i = 0; i < id.length(); i++) {
//前17位不是数字不合法,判断是不是前17位,判断每位是不是数字
if (i < id.length() - 1) {
if (id.charAt(i) < '0' || id.charAt(i) > '9') {
return false;
}
}
//最后一位不是数字或者最后一位不是X不合法,判断是不是最后一位,判断是不是数字,是不是X;
else if(i==id.length()-1){
if (id.charAt(i) <= '0' && id.charAt(i) >= '9' && id.charAt(i) != 'X') {
return false;
}
}
}
return true;
}
}
|
|