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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:31:47+00:00 2026-05-17T22:31:47+00:00

level: beginner Below snippet is part of code that counts letters in an array.

  • 0

level: beginner

Below snippet is part of code that counts letters in an array. How do you say this in english?

counts[letters[i] - 'a']++ ;

I understand the substraction mechanism but i’m a bit confused by the shorthand way to write the letter count incrementation.

full code:

class CountLettersInArray 
{
    public static void main(String[] args) 
    {
        char[] letters = new char[100] ;

        for (int i = 0 ; i < 100 ; i++ )
        {
            letters[i] = RandomCharacter.getRandomLowerCaseLetter() ;
        }

        int[] counts = new int[26] ;

        for (int i = 0 ; i < 100 ; i++ )
        {
            counts[letters[i] - 'a']++ ;
        }

        for (int i = 0 ; i < 26 ; i++ )
        {
            System.out.print(counts[i] + " " ) ;
        }

    }
}
  • 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-17T22:31:48+00:00Added an answer on May 17, 2026 at 10:31 pm

    What is happening here, is that the letter a is a char, which has an integer value of 97.

    So, by taking the character value, and subtracting the ascii value of ‘a’, it is making the array base zero. So, for each character it is incrementing the value in the array (remember all array values in an integer array start at zero).

    So, it increments the relevant characters count in the array each time a character is found.

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

Sidebar

Related Questions

query level: beginner As part of a learning exercise I have written code that
This is a beginner level question for asp.net MVC I have the following code
Excuse the beginner level of this question. I have the following simple code, but
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
This is a beginner-level question. I have a catalog of mtypes: mtype_id name 1
Level: Beginner I'm doing my first steps in Object Oriented programming. The code is
level: beginner the following code will print 'False' def function(x): if len(x) == 5:
Level: Beginner In the following code my 'samePoint' function returns False where i am
This stems from my question that i started at MVC Beginner Question Im now
I'm looking for suggestions for a beginner level ASP/XML test. Essentially I'm trying to

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.