测试数据
it is so 666 really 6666 what else can I say 6666666666
执行结果
it is so 666 really 9 what else can I say 27
import java.util.Scanner;
//import java.util.TreeMap;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//输入字符串
String str = sc.nextLine();
//按空格切分,使用一维数组接收
String[] str1 = str.split(" ");
for (int i = 0; i < str1.length; i++) {
//定义变量作为判断条件
int h = 0;
for (int j = 0; j < str1[i].length(); j++) {
//比较数组中每个元素的单个字符
if (str1[i].charAt(j) == '6') {
h++;
}
//数组中有非'6'的字符,则终止判断,将h置为0
else {
h = 0;
break;
}
}
//判断符合条件的h的值,判断是否进行字符串的判断
if (h >= 4 && h < 10) {
str1[i] = "9";
} else if (h >= 10) {
str1[i] = "27";
}
}
//输出新的字符串
for (int i = 0; i < str1.length; i++) {
//判断是否为数组的最后一个元素,如果是则不加空格
if (i == str1.length - 1)
System.out.print(str1[i]);
else {
System.out.print(str1[i] + " ");
}
}
}
}