题解 | #表示数字#

表示数字

https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.nextLine();
            StringBuilder ss = new StringBuilder();
            for(int i =0;i<str.length();i++){
                int first=0;
                if(i>0) first = str.charAt(i-1);
                int last = str.charAt(i);
                if(i>0&&(((first>='0'&&first<='9'&&(last<'0'||last>'9'))||(last>='0'&&last<='9'&&(first<'0'||first>'9'))))){
                    ss.append("*");
                    ss.append(str.charAt(i));
                }else if(i==0&&last>='0'&&last<='9'){
                    ss.append("*");
                    ss.append(str.charAt(i));
                }else ss.append(str.charAt(i));
                if(i==str.length()-1&&last>='0'&&last<='9'){
                    ss.append("*");
                }
            }
            System.out.println(String.valueOf(ss));
        }
    }
}

全部评论

相关推荐

下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务