Description
输入一个字符串str1,把其中的连续非数字的字符子串换成一个‘’,存入字符数组str2 中,所有数字字符也必须依次存入 str2 中。输出str2。
Input
输入为一行字符串str1,其中可能包含空格。字符串长度不超过80个字符。
Output
输出处理好的字符串str2。
Sample
Input
$Ts!47&s456 a23 +B9k
Output
47456239**
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
char[] str1 = new char[85];
char[] str2 = new char[85];
str1 = reader.nextLine().toCharArray();
int j = 0;
if (str1[0] >= '0' && str1[0] <= '9')
str2[j++] = str1[0];
else
str2[j++] = '*';
for (int i = 1; i < str1.length; i++) {
if (str1[i] >= '0' && str1[i] <= '9') {
str2[j++] = str1[i];
} else if (str2[j - 1] != '*')
str2[j++] = '*';
}
for (int i = 0; i < j; i++) {
System.out.print(str2[i]);
}
reader.close();
}
}
版权声明:本文为baiqiaoxiang原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。