title: How to treat a string as a variable in java?
body: <p>Remember playing the game when you indexed each of the words of your name and added it all together to form a secret number? Like <code>aay</code> would be <code>1+1+25=27</code></p>
  
  <p>I tried to do the same thing by various methods in java but I failed.Let me share my script first and then tell what all i tried.</p>
  
  <pre><code>class test{
      public static void main(String args[]){
          int c = 3;
              String s = "c";
          ///now this is what all i tried:
  
          int value1 = (int)(s);
          ///i tried a cast, but that failed.
  
          String d = "4";
          int value2 = Integer.parseInt(d);
          ///when i try this, it correctly converts the string to an integer.
  
          Integer.parseInt(s);
          ///but when i try the above, it fails to do the same.
      }
  }
  </code></pre>
  
  <p>In this code, I try 2 different methods both of which are working in a similar way that I want to but not exact.</p>
  
  <p>The problem is that it couldn't reorganize that c is a variable that has an integer value.</p>
  
  <p>So, is there any shortcut to do it?
  Also, right now the string is only 1 digit long, once the user inputs his or her name, I shall use a for loop to loop all of the letters completely.</p>
  
  <p>If there isn't any shortcut, is the only option left with me is to make an if statement like:</p>
  
  <pre><code>if(letter=a;){
      value=1;
  } 
  </code></pre>
  
  <p>Or something like that?</p>
  
  <p>thanks for helping!</p>