满意答案
o莫非如此o
2019.03.21
采纳率:55% 等级:7
已帮助:160人
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一串字符");
String str = sc.nextLine();
String strFilter = filter(str);
System.out.println("过滤后:" + strFilter + "\n字母个数:" + strFilter.length());
sc.close();
}
private static String filter(String str) {
StringBuffer sb = new StringBuffer("");
for (int i = 0; i
char c = str.charAt(i);
if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
sb.append(c);
}
return new String(sb);
}
}
00分享举报