HWOJ将一个字符中所有出现的数字前后加上符号“*”,其他字符保
2017-02-17 本文已影响0人
Yuu_CX
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner s = new Scanner(System.in);
String a = s.nextLine();
StringBuffer sb = new StringBuffer();
s.close();
a="y"+a+"c";
for(int i=0;i<a.length()-1;i++){
if((!isNum(a.charAt(i))&&isNum(a.charAt(i+1)))||(isNum(a.charAt(i))&&!isNum(a.charAt(i+1)))){
sb.append(a.charAt(i)).append("*");
}else{
sb.append(a.charAt(i));
}
}
System.out.println(sb.substring(1));
}
public static boolean isNum(char c){
if(c>='0'&&c<='9'){
return true;
}else {
return false;
}
}
}