import java.util.Scanner;
public class Numbers
{
public static void main(String[] args) {
System.out.println("输入一个字符串:");
Scanner scanner = new Scanner(System.in);
StringBuffer sb=new StringBuffer();
String line = scanner.nextLine();
char a[]=line.toCharArray();
System.out.println("打印出其中所有的数字:");
for (int i = 0; i < a.length; i++)
{
if(Character.isDigit(a[i]))
sb.append(a[i]);
}
System.out.println(sb);
}
}
输入一个字符串:
asfafas2124124sdgd11
打印出其中所有的数字:
212412411