方法一:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.next(); char[] ch = str.toCharArray(); for (int i = 0; i < ch.length; i++) { if ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')) { System.out.print(ch[i]); } } } }
方法二:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.next(); for (int i = 0; i < str.length(); i++) { if ((str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') || (str.charAt(i) >= 'a' && str.charAt(i) <= 'z')) { System.out.print(str.charAt(i)); } } } }
方法三:
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.next(); char[] ch = str.toCharArray(); for (int i = 0; i < str.length(); i++) { if (Character.isLetter(ch[i])||Character.isUpperCase(ch[i])) { System.out.print(ch[i]); } } } }
方法四:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { System.out.println(in.nextLine().replaceAll("[^a-zA-Z]+","")); } in.close(); } }
0.0分
0 人评分
C语言训练-求函数值 (C语言代码)浏览:976 |
C语言训练-素数问题 (C语言代码)浏览:1696 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:782 |
简单的a+b (C语言代码)浏览:385 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:485 |
Wu-求圆的面积 (C++代码)浏览:1994 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:863 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:683 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:699 |
1012题解浏览:938 |