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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:58:47+00:00 2026-05-26T19:58:47+00:00

for (int i = 0; i < s.length(); ++i) { if (s.charAt(i) >= ‘A’

  • 0
for (int i = 0; i < s.length(); ++i) 
    {
        if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') 
        {
            ++array[s.charAt(i) - 'A'];
        }
    }

I understand the For loop. the s.length() is 26, int[26] to be exact. so this loop will occur 26 times, 0-25. If the Char at i, 0-25 is between or are A-Z it will then proceed to ++array[s.charAt(i) - 'A']; From what i see it adds array once per loop, or adds the value of array once per loop, for the String at char i so the first one would be 0 second would be 2, because arrays start at 0. so adding an array at location of i -'A' is where i get confused.

  • 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-26T19:58:48+00:00Added an answer on May 26, 2026 at 7:58 pm

    The statement ++array[s.charAt(i) - 'A']; is incrementing the value in the array indexed by s.charAt(i) - 'A'.

    What this loop does is that it counts up the number of occurrences of each letter in s.

    The reason for - 'A', is that it “shifts” the ascii/unicode value so that A - Z have values 0 – 25. And are thus more suitable as an array index.

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

Sidebar

Related Questions

Why is Array.Length an int, and not a uint . This bothers me (just
any problems with doing this? int i = new StreamReader(file.txt).ReadToEnd().Split(new char[] {'\n'}).Length
int length = strlen(src); char *structSpace = malloc(sizeof(String) + length + 1); String *string
unsigned int *pMessageLength, MessageLength; char *pszParsePos; ... //DATA into pszParsePos ... printf(\nMessage Length\nb1: %d\nb2:
I have this method: public static int what(String str, char start, char end) {
I have the following code public static int unknown(String x) { if ((x.length()==1) &&
for(int i=0;i<number.length();i++){ if(number.charAt(i)==0){ nums[i]=11; System.out.println(bob); }else{ nums[i]=number.charAt(i); } } I am trying to get
I have the code: unsigned int length = strlen(somestring); I'm compiling with the warning
int bufferlength = 12488; int pointer = 1; int offset = 0; int length
double d[10]; int length = 10; memset(d, length * sizeof(double), 0); //or for (int

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.