2016-11-06 5 views
1

このエラーを示す次のコードブロック、それはライン ランタイムException-はまだ

char arr [] = w.toCharArray(); 

そして、他のコンパイラで

に達したとき、jelliotに「ランタイムException-はまだ実装されていない機能は」実装できない機能、それは勝ちましたそれは取るべき入力の数を取る。 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(); 
    } 
+0

私は集合N = 4場合は、 '、それだけで、それはあなたが使用している3およびJavaのバージョンを取るように2 inputs.'は思わとり、' CharArray'をサポートしていませんか? –

+0

"jeliot"とはどのようなものかを説明できますか?あなたがしようとしていることを完全にサポートしていないライブラリ/アプリケーションのようです。 –

+0

これはcount <= nであり、count

答えて

0

例外はStringクラスのこの特定の方法(toCharArray())は、使用しているのjavaの(おそらく非標準)の実装のために実装されていないことを示しています。この問題を回避するには、char配列を使用せず、代わりに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(); 
} 
+0

!ありがとう! –

関連する問題