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 6612369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:05:25+00:00 2026-05-25T20:05:25+00:00

I am having a few problems in getting a method to work properly in

  • 0

I am having a few problems in getting a method to work properly in Java. In the program I have created an array consisting of many different words of different length. The method I’m working on is supposed to read user input for wordlength, letter, and position, and Java will then print out any words matching these three parameters (for instance, if the user types wordlength 4, letter A and position 2, and words with length 4 containing the letter A at position 2 will be printed out).

Anyhow, the method I have created looks like this:

public static void inputMethod(int length, char letter, int position){
    for (int index = 0; index < wordTable.length; index++) {
        if (length == wordTable[index].length() && letter == wordTable[index].charAt(position) )
            System.out.println(wordTable[index]); }

This method works fine for for some inputs, but for other inputs I get an error message such as this:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(Unknown Source)
at Wordarray.inputMethod(Wordarray.java:153)
at Wordarray.main(Wordarray.java:61)

If anyone could explain to me how I can fix this, I would greatly appreciate it! Like I said, I only get this message for certain inputs. For other inputs the program works just like it is supposed to.

  • 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-05-25T20:05:25+00:00Added an answer on May 25, 2026 at 8:05 pm

    If you have replaced

    for (int index = 0; index < wordTable.length; index++) {
    

    with

    for (int index = 0; index < length; index++) {
    

    that is most likely not what you really want.

    The better approach would be like this:

    public static void inputMethod(int length, char letter, int position) {
      // check if input is valid
      if(position < length)
        for (int index = 0; index < wordTable.length; index++) {
          if (length == wordTable[index].length() && letter == wordTable[index].charAt(position) )
                System.out.println(wordTable[index]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning all, I'm having a few problems with a method in my C#
I am having some problems getting this animation to execute. I have a feeling
I have been having multiple problems with getting the Add View.. Create a strongly-typed
I've been having some problems with a few Fan Pages and getting their details
I am having problems getting the desired behavior out of these few classes and
I'm having a few problems getting my listview to show up in a simple
So I am having a few problems with settings this up. Let me explain.
I've been having a few problems running PHP-based utilities within the command line ever
I have a File having text and few numbers.I just want to extract numbers
I'm implementing a small game and am having trouble getting the physics working properly.

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.