package Demo02;
import java.nio.charset.StandardCharsets;
import java.util.Random;
public class Demo06_plus {
public static void main(String[] args) {
String str1 = "哈喽大家好,我是酷满月风";
String over = card(str1);
System.out.println(over);
}
public static String card (String str1){
char[] chars = "!@#¥%……&*()+——".toCharArray();
//System.out.println(array1);
int index = str1.indexOf(",");
String str2 = "[";
for (int i = 0; i < str1.length(); i++) {
char ch = str1.charAt(i);
Random r =new Random();
int num = r.nextInt(11);//随机数部分
if (i == str1.length()-1){ //判断是否结尾,并跳出
str2 += chars[num] + "]";
break;
}
if(index!=i) { //判断逗号,并截取
str2 += chars[num] + str1.substring(i, i + 1);
}
}
return str2;
}
}
记录,成长。
接收并感谢大家的指导优化。