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();
}
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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.