表示数字(Java)
表示数字
http://www.nowcoder.com/questionTerminal/637062df51674de8ba464e792d1a0ac6
JAVA
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ int flag = 0; StringBuilder sb = new StringBuilder(); char[] arr = in.nextLine().toCharArray(); for (int i = 0; i < arr.length; i++){ if (isNumber(arr[i]) && flag == 0){ sb.append('*'); sb.append(arr[i]); flag = 1; }else if (!isNumber(arr[i]) && flag == 1){ sb.append('*'); sb.append(arr[i]); flag = 0; }else{ sb.append(arr[i]); } } if (isNumber(arr[arr.length - 1])) sb.append('*'); System.out.println(sb.toString()); } } private static boolean isNumber(char c){ if (c >= '0' && c <= '9') { return true; } else { return false; } } }