-2

私はJavaが初めてで、ツイートの#、@、およびリンクをカウントする割り当てがあります。このプログラムを書いたところ、コンパイラはエラーを認識しませんが、実行してつぶやきを入力すると、エラーが表示されます。

 public static void main (String str[]) throws IOException {
      Scanner scan = new Scanner(System.in);

      System.out.println("Please enter a tweet.");
      String tweet=scan.nextLine();
      int quantity = tweet.length();
      System.out.println(tweet);
      if (quantity > 140)
      {
        System.out.println("Excess Characters: " + (quantity - 140));
      }
      else{
        System.out.println("Length Correct");
        int hashtags=0;
        int v=0;
        if (tweet.charAt(0)=='#'){
        hashtags++;
        v++;
        }
        String teet=tweet;
          while (hashtags != v-1){
          v++; 
          int hashnum= teet.indexOf('#');
          if ((teet.indexOf('#')!=-1) && (teet.charAt(hashnum + 1)!=(' ')) && (teet.charAt(hashnum-1)==(' '))) {
             hashtags++;
          }
          if (teet.indexOf('#')!=-1) {
          teet=teet.substring((hashnum+1),(quantity));
               }
          }
        System.out.println("Number of Hashtags: " + hashtags);
        int ats=0;
        int w=0;
        if (tweet.charAt(0)=='@'){
          ats++;
          w++;
        }
        String tweat=tweet;
        while (ats != w-1){
          w++;
          int atnum= tweat.indexOf('@');
          if ((tweat.indexOf('@')!=-1) && (tweat.charAt(atnum + 1) !=(' ')) && (tweat.charAt(atnum-1)==(' '))) {
            ats++;
          }
          if (tweat.indexOf('@')!=-1) {
          tweat=tweat.substring((atnum+1),(quantity));
          }
        }
        System.out.println("Number of Attributions: " + ats);

 }
 }
 }

助けてくれる人に感謝します。

4

1 に答える 1