运行时异常 - 功能尚未实现

Runtime Exception- feature not implemented yet

以下代码块在 jelliot 中显示此错误 "Runtime Exception- feature not implemented yet",当它到达第

行时
char arr [] = w.toCharArray();

而在其他编译器中,它不会采用它应该采用的输入数量。如果我设置n=4,它只需要2个输入。

    Scanner Sc = new Scanner (System.in);
    int n = Sc.nextInt();
    for(int count = 1;count<=n; count++){
        String w = Sc.nextLine();
        char arr [] = w.toCharArray();
        if(arr.length > 4){
            System.out.print(arr[0]);
            System.out.print(arr.length-2);
            System.out.print(arr[arr.length-1]);
        }
        else{
            System.out.println(w);
        }
        System.out.println();
    }

异常表明 String class 的这个特定方法 (toCharArray()) 没有为 java 的(可能是非标准的)实现实现你正在使用的。您可以通过不使用字符数组来解决这个问题,而是使用 String 方法 length()charAt()。试试这个:

Scanner Sc = new Scanner (System.in);
int n = Sc.nextInt();
for(int count = 1;count<=n; count++){
    String w = Sc.nextLine();
    if(w.length() > 4){
        System.out.print(w.charAt(0));
        System.out.print(w.length()-2);
        System.out.print(w.chatAt(w.length()-1));
    }
    else{
        System.out.println(w);
    }
    System.out.println();
}