Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8316007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:15:34+00:00 2026-06-08T21:15:34+00:00

Looking for help with a basic array problem. Program has to read a sentence

  • 0

Looking for help with a basic array problem. Program has to read a sentence and store the frequencies of the word lengths in an array and then print out how many words are 1 letter words, 2 letter words etc.

I’m a pretty raw java programmer but have made a stab at it below would greatly appreciate some guidance. What I have seems to compile but spits out some garbled hex when I run the program and enter a sentence.

When I enter a sentence into the program I get an output like this:

[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf
[I@eb42cbf

My code:

class WordCount
{
    public static void main(String[] args)
    {
        int wordList[] = new int[20];
        System.out.println("Please enter a sentence.");

        for (int i = 0; i <= wordList.length; i++)
        {
            String s = Console.readToken();
            int x = s.length();
            wordList[x]++;
        }

        int x = 1;

        while (x < wordList.length)
        {
            if (wordList[x] > 0)
                System.out.println(x + "-letter words: " + wordList[x]);
            x++;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:15:35+00:00Added an answer on June 8, 2026 at 9:15 pm

    Here are my suggestions:

    • use a Scanner instead of your Console.readToken, which is not part of the standard JDK
    • use standard variable names (i for a counter is better than x)
    • the rest of your code works fine
    • but I would use a for loop instead of the while because you know how many times you need to loop

    Here is my version – The changes are: use of a scanner, renaming x into i and changing the while loop into a for loop:

    public static void main(String[] args) {
        int wordList[] = new int[20];
        System.out.println("Please enter a sentence.");
        Scanner scanner = new Scanner(System.in); //Use a scanner, part of the standard JDK
    
        for (int i = 0; i <= wordList.length; i++) {
            String s = scanner.next(); //reads the next string
            int length = s.length();
            wordList[length]++;
        }
    
        for (int i = 0; i < wordList.length; i++) { //use a for loop
            if (wordList[i] > 0) {
                System.out.println(i + "-letter words: " + wordList[i]);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for any beyond basic resources that can help me to be proficient
I'm looking for help to create a query, to solve the following problem: Let's
I'm working on a basic eCommerce site and I am looking for some help
I'm looking for help on developing a MS Access form that has Google Maps
I am looking for help with the database scheme, not the actual cloud itself.
I am looking for help in determining if the class model that I am
I'm looking for help with my query below. which is never returning anything for
I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)
It is quite possible that I'm just looking for help finding the name of
LINQ gurus, I am looking for help to write a query... I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.