判断数字后放到字符数组不太好,因为不知道大小,放到stringbuffer比较好一些
- import java.util.*;
- public class Test
- {
- public static void main(String[] args)
- {
- String string = null ;
- Scanner scanner = new Scanner(System.in);
- string=scanner.next();
- System.out.println(sop(string));
- }
- public static StringBuffer sop(String string)
- {
- StringBuffer sbf =new StringBuffer();
- char ch[]=string.toCharArray();
- for (int i = 0; i < ch.length; i++)
- {
- if (ch[i]<48||ch[i]>57)
- {
- sbf.append(ch[i]);
- }
- }
- return sbf;
- }
- }
复制代码 |