How many different variable names are there in JAVA?

439 Views Asked by At

Please edit the topic because I don't know where to put this. Thanks.

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?

My Work

Product rule: Suppose any task is split into two parts. If there is $n_1$ ways to do the first task and $n_2$ ways to do the second task, then number of ways to perform the task is $n=n_1*n_2\textrm{ ways}$

Sum rule: If any task can be done in either of $n_1$ ways or $n_2$ ways, then total number of ways to perform the task is $n=n_1+n_2\textrm{ ways}$

Since the variable is a string of between 1 and 65,535 characters. The variable can be an uppercase or a lowercase letter, a dollar sign, an underscore, or a digit except the digit is not the first characters.

If the first letter is not a digit, then the number of choices for the character = $2(26)+1+1=54$

The number of choices for the remaining characters = $2(26)+1+1+10=64$

Therefore, total number of different variables names is determined by

$\sum _{ i=1 }^{ 65536 }{ 54(64^ {i-1}) } $

$=(54)\frac {64^{55536}-1 }{64-1 } $

$= \frac {54(64^{55536}-1) }{63 } $

Please verify my answer and also provide if there is an easy alternate solution

1

There are 1 best solutions below

0
On

I think the summation must be 1-65535 and then the powers must be adjusted according to that, as it is mentioned in the Determine the number of different variable names