Problem Description
輸入一個字符串str1,把其中的連續非數字的字符子串換成一個‘*’,存入字符數組str2 中,所有數字字符也必須依次存入 str2 中。輸出str2。
Input
輸入爲一行字符串str1,其中可能包含空格。字符串長度不超過80個字符。
Output
輸出處理好的字符串str2。
Example Input
$Ts!47&*s456 a23* +B9k
Example Output
*47*456*23*9*
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner reader=new Scanner(System.in); String s1,s2; int i,flag=0; s1=reader.nextLine(); char a[]=new char[100]; a=s1.toCharArray(); for(i=0;i<a.length;i++) { if(a[i]>='0'&&a[i]<='9') { System.out.printf("%c", a[i]); flag=0; } else { if(flag==0) { System.out.printf("*"); flag=1; } } } } }