在遍历字符串时在我的输出中获取 Ljava.lang.String;@

Getting Ljava.lang.String;@ in my output while iterating through a string

所以我必须为作业编写一个程序,为此我必须接受一个字符串,确保它有正确数量的句子并打印每个单词的频率。我几乎完全正确,但最后,当我打印单词(我存储在数组中)时,每个单词前面都有 Ljava.lang.String; @xyznumber。我不知道为什么会这样,也无法在网上找到解决方案。这是我的代码:

import java.util.Arrays;
import java.io.*;

class frequency
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the number of sentences");
        int cS = Integer.parseInt(br.readLine());
        System.out.println("Enter sentences");
        String s = br.readLine();
        int cS1 = 0;
        int cW = 0;

        for(int i = 0; i < s.length(); i++)
        {
            char ch = s.charAt(i);
            if (ch=='.'||ch=='?')
            {
                cW++;
                cS1++;
            }
            if (ch==' ')
            {
                cW++;
            }
        }

        if (cS1!=cS)
        {
            System.out.println("You have entered the wrong number of sentences. Please try again.");
        }
        else
        {
            int c = 0;
            int d = 0;
            String a[] = new String[cW];
            System.out.println("Total Number of words: "+cW);
            for (int i= 0;i<s.length();i++)
            {
                char ch=s.charAt(i);
                if (ch==' '||ch=='?'||ch=='.')
                {
                    a[c++]=a+s.substring(d,i);
                    d = i+1;
                }
            }

            int length=0;
            firstFor: for(int i=0;i<a.length;i++)
            {
                for(int j=0;j<i;j++)
                {
                    if (a[j].equalsIgnoreCase(a[i]))
                    {
                        continue firstFor;
                    }
                    else
                    {
                        length++;
                    }
                }
            }

            String words[] = new String[length];
            int counts[] = new int[length];
            int k=0;
            secondFor: for (int i =0;i<a.length;i++)
            {
                for(int j = 0; j<i;j++)
                {
                    if (a[j].equalsIgnoreCase(a[i]))
                    {
                        continue secondFor;
                    }

                }
                words[k]=a[i];
                int counter = 0;
                for (int j =0;j<a.length;j++)
                {
                     if(a[j].equalsIgnoreCase(a[i]))
                     {
                        counter++;
                     }
                }
                counts[k]=counter;
                k++;
            }
            for (int i=0;i<words.length;i++)
            {
                System.out.println(words[i]+"\n"+(counts[i]));
            }
        }
    }
}

问题出在这行:

a[c++]=a+s.substring(d,i);

由于 a 是一个 String 数组,它所做的是将 a 中的元素之一分配为等于整个数组的 String 表示, 加上 s 的子串。虽然数组没有非常有用的 String 表示,但这是您看到的 Ljava.lang.String;@xyznumber 的来源。

根据您希望 a[c] 的第一部分是什么,使用数组的索引,或者 convert the array to a String