Mahjabin Meem Mahjabin Meem - 26 days ago 14
Java Question

Runtime Exception- feature not implemented yet

The following block of code showing this error "Runtime Exception- feature not implemented yet" in jelliot, when it reaches the line

char arr [] = w.toCharArray();


And in other compilers,it won't take the number of input it's supposed to take. If I set n=4, it only takes 2 inputs.

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();
}

Answer

The exception indicates that this particular method (toCharArray()) of the String class isn't implemented for the (presumably non-standard) implementation of java that you're using. You can work around this by not using a char array, and instead using the String methods length() and charAt(). Try this:

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();
}
Comments