标题: 技术贴 [打印本页] 作者: 周智超 时间: 2019-4-1 19:38 标题: 技术贴 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();