View Code of Problem 50

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        StringBuilder str2 = new StringBuilder();
        boolean tag = true;

        for(int i = 0; i < str1.length(); i++) {
            char c = str1.charAt(i);

            if(c >= '0' && c <= '9') {
                str2.append(c);
                tag = true;
             } else if(tag) {
                str2.append("*");
                tag = false;
            }
        }

        System.out.println(str2);
    }
}

Double click to view unformatted code.


Back to problem 50