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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:00:36+00:00 2026-06-15T18:00:36+00:00

EVerytime I write any code similar to this one, I get this type of

  • 0

EVerytime I write any code similar to this one, I get this type of error.
It’s building a file but not letting it run, it just throws exception. I’m not familiar with exceptions as i am a beginner kindly help me out and specifically point out the mistake that I’m making.

public static void main(String args[]) {
    String name = "Umer Hassan";
    String name1 = "Hassan Umer";
    char[] name2 = new char[name.length()];

    for (int j = 0; j <= name.length(); j++) {
        for (int i = 0; i <= name.length(); i++) {
            if (name.length() == name1.length()) {
                if (name.charAt(i) == name1.charAt(i)) {
                    name2[i] = name1.charAt(i);
                }
            }
        }
    }
}

When I run the program it shows the following error:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 11
    at java.lang.String.charAt(String.java:658)
    at Anagram.main(Anagram.java:24)
  • 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-15T18:00:37+00:00Added an answer on June 15, 2026 at 6:00 pm

    Your loop control variables (i / j) are going up to name.length() – which is an out of bounds index (since the max index of a string/list is len - 1 – remember the first index is 0).

    Try using i < name.length() and j < name.length() as the loop conditions instead.

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

Sidebar

Related Questions

I need to write the following line of code: ((eq item #\) (do-this...)) But
My question is really simple, but apparently nobody's experienced a similar error. I'm writing
I want to write Jquery code in master file, so that if there if
I am trying to write data to a php file everytime the page is
I understand these are necessary...of course to write proper code, but is there a
I am trying to export a report but everytime it runs the code to
I need to have a newline every time I write to a file in
I went through answers on similar topics here on SO but could't find a
I'm trying to write a function to return the word string of any number
Please consider this simplified example: type TForm43 = class(TForm) drwgrd1: TDrawGrid; procedure drwgrd1DrawCell(Sender: TObject;

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.