//假设已知随即凌乱字符 String a = "1n21ewmnd22 asmnciushvla*/-*/!@#$%^&* ()(*&^"; //定义接收b; String b = ""; for (int i = 0; i < a.length(); i++) { //是否含有数字,有则接收 if ("1234567890".contains(a.charAt(i)+"")) { b+=a.charAt(i); } } //最后输出 System.out.println(b);
//假设已知随即凌乱字符 String a = "1n21ewmnd22 asmnciushvla*/-*/!@#$%^&* ()(*&^"; //定义接收b; String b = ""; for (int i = 0; i < a.length(); i++) { //是否含有数字,有则接收 if ("1234567890".contains(a.charAt(i)+"")) { b+=a.charAt(i); } } //最后输出 System.out.println(b);