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

  • Home
  • SEARCH
  • 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 8563269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:55:22+00:00 2026-06-11T16:55:22+00:00

Code first questions later… public class Program2 { //The custom word object used when

  • 0

Code first questions later…

public class Program2 
{
//The custom word object used when parsing the input file
class Word
{
    public String wordname;
    public int count;
    public int uniqueWord = 0;

    public Word(String word)
    {
        wordname = word;
        count = 1;
    }

    public boolean wordExists(String word)
    {
        if (word == this.wordname)
        {
            this.count++;
            return true;
        }
        else
        {
            return false;
        }   
    }

    public int getCount(Word word)
    {
        return this.count;
    }

    public String getName(Word word)
    {
        return this.wordname;
    }

}


// The main method
public static void main(String[] args) throws IOException
{
    //new array of words size 100
    Word[] words = new Word[100];
    //set the first word to bananna
    Word words[0] = new Word("bananna");
    //print bananna
    System.out.print(getName(words[0]));
}
}

Ok, so with what I know about Java, the code above should let me make an array of words, set the first to “bananna”, and print it out. I have little experience making a custom class like this, and I can’t find a good resource to model. Also, I am not 100% sure I understand calling static/nonstatic methods, so I’m sure some of the errors are from that as well.

What the program should do eventually, as a reference for why I am doing this, I have to take information in from a file (delimited strings aka Words) and see if it already exists in the array of words (and increment that word’s count if it does), if it doesn’t then make a new word.

Errors I’m getting are here:


Program2.java:116: ']' expected
            Word words[0] = new Word("bananna");
                       ^
Program2.java:116: illegal start of expression
            Word words[0] = new Word("bananna");
                        ^
2 errors

Any other information that you need let me know. I’ll be back to check this post in an hour. Thank you for any help you have!

  • 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-11T16:55:23+00:00Added an answer on June 11, 2026 at 4:55 pm
    Word words = new Word[100];
    

    Your main problem I can see is that Word[100] is an Array type that holds Word objects. You’ll need the words variable to be of type Word[], not just of type Word.

    Regarding static and non-static, think of it this way: You’ve written a Word class, and then you can create as many Word objects as you like that belong to that class. When something is static, it means it belongs to the Word class, so it belongs to the definition of a word without belonging to any particular word. In contrast, something that is not static will belong to a particular Word object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some questions with relationship of ef code first. My code: public class
I'll post my code first, and then ask questions. def menu(**arg): if len(arg) ==
This questions involves 2 different implementations of essentially the same code. First, using delegate
I have this view (DetailsContainer, first class in code section of this question) with
my first question here! I have a problem with a piece of code that
I apologize for making my first question not the hard-hitting code-related question I was
I have a question about defining Foreign Key in EF Code First Fluent API.
This is my first question on stackoverflow. I just wonder why my getJSON code
So, here's my question: Why won't the code in the first snippet work when
First off, sorry if this is a stupid question. I installed code::blocks to try

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.