The name of a variable in the JAVA programming language is a string of $1$ to $65,535$ characters, where each character can be an uppercase or a lowercase letter, a dollar sign, an underscore, or a digit. Furthermore, the first character in the string must not be a digit. How many different variable names are there in JAVA?

Hint Given:

I know there are the following characters:

  • $26$ Lowercase Letters
  • $26$ Uppercase Letters
  • $1$ Dollar Sign ($) - $1$ Underscore(_)

For a total of $54$ ways.

I am unsure where to go from this point. If this could be worked out with an explanation it would be much appreciated.

  • 2
    $\begingroup$ Have you tried working out the count of variable names for a couple characters, say, $1,2,3,4,\dots$ characters in length? $\endgroup$ – abiessu Apr 25 '18 at 2:25

Hint: Do you recognize the exponent on $r$ as the number of characters after the first? How many one character names are there? What does that represent?

| cite | improve this answer | |
  • $\begingroup$ That makes sense. If the string has only one character, there are 54 possibilities since the first character must not be a digit. If the string has two characters, there are 54 * 64 possibilities and so on. So would the geometric series be 54 * 1 * (64^65535 - 1) / (64 - 1) equaling 54 * (64^65535 - 1) / 63? $\endgroup$ – John Larkos Apr 25 '18 at 2:57
  • $\begingroup$ That is correct. $\endgroup$ – Ross Millikan Apr 25 '18 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.