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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:14:48+00:00 2026-06-01T13:14:48+00:00

If I have a string that contains Cat how could I check before hand

  • 0

If I have a string that contains “Cat”
how could I check before hand if anything exists in each individual charAt case.
Here is the sample code

    for (int i = 0; i < array.length; i++)
    {
        System.out.println();
        for (int j = 0; j < size; j++)
        {
            System.out.print(array[j].charAt(i) + " ");
        }
    }

Once i reaches 3 you would get an out of bounds exception. Is there a way that it could print an empty space?

EDIT: Sorry I wasn’t clear at all. There are multiple strings that are being printed vertically. So assume the largest string is size of 10 and that the smallest is size of 4. The first four char of each string print fine. But an out of bounds error occurs when the fifth char tries to print since it doesn’t exist. Is there any way around that?

  • 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-01T13:14:49+00:00Added an answer on June 1, 2026 at 1:14 pm

    You’ve got i and j the wrong way around, that’s all.

    You should have:

    System.out.print(array[i].charAt(j) + " ");
    

    And to make your code more robust, you should rewrite the inner loop to go until it reaches the length of array[i], instead of a pre-defined size variable.

    Update: If you want to print the array of strings vertically (so each string is in a column), this is what your code should look like:

    for (int i = 0; i < size; i++)             // i is the loop variable for the character count, we'll print one line for each character
    {
        for (int j = 0; j < array.length; j++) // for every string in the array
        {
            char c = ' ';                      // print out a space character by default to keep the columns aligned
            if ( array[j].length() > i )       // but if the array[j] still has characters left
                c = array[j].charAt(i);        // print that character instead
            System.out.print(c + " ");         // here
        }
        System.out.println();                  // and close the line
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that contains a known number of double values. What's the
I have a string that contains a czech character. the string is 0bálka This
If I have a string that contains a url (for examples sake, we'll call
Suppose I have a string that contains Ü. How would I find all those
If I have a string that contains the html from a page I just
I have a string of text that contains html, and I need to extract
I have a C# string object that contains the code of a generic method,
I have some code in a python string that contains extraneous empty lines. I
I have a AJAX request that will return a string that contains some HTML
I have string that contains 1.3 and I am checking with Date.TryParse method. It

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.