题解 | #表示数字#

表示数字

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.hasNextLine()) { // 注意 while 处理多个 case
            char [] a = in.nextLine().toCharArray();
            if (Character.isDigit(a[0])) {
                System.out.print("*");

            } 
            for (int i = 0; i < a.length - 1;) {
                if (!Character.isDigit(a[i]) && Character.isDigit(a[i + 1]) ||
                        Character.isDigit(a[i]) && !Character.isDigit(a[i + 1]) ) {
                    System.out.print(a[i] + "*");

                } else {
                    System.out.print(a[i]);
                }



                i++;
            }
           
                if (Character.isDigit(a[a.length - 1])) {
                    System.out.print(a[a.length - 1] + "*");

                } else {
                    System.out.print(a[a.length - 1]);
                }
            
        }
    }
}

全部评论

相关推荐

图源网络侵权删
dddooola:这个事情我去年8月就看到有人b站(up:程序员正义)在举报了,可能一直在查,这次是查明后的处分了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务