title: Method to return string
body: <p>So I'm doing a simple encryption program in Java. The user inputs a string (strTarget), and then that string is taken to this function. In the for-loop, it should take the character's ASCII value, reduce it by 4, and then return it to the string (doing that for all characters in the string). As you see my friends, I have already done that, however, I am not sure on how to reconstruct the string that I wish to get back (e.g. if a user inputs 'efg', the returned string should be 'abc')</p>
  
  <p>So, here's the result I got with the suggestions. I'm obviously doing something wrong in the Menu class, not sure what it is. It stops working when I input a string to be encrypted.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Menu {
  
  public static String strTarget;
  
  public static void main(String[] args) {
  
  
      Scanner in = new Scanner(System.in);
  
      System.out
              .println("Welcome to the encr/decr program");
      System.out
              .println("To encrypt a string, press 1, to decrypt a string, press 2");
      int choice = in.nextInt();
      if (choice == 1) {
          System.out.println("Type the string you want to encrypt.");
          strTarget = in.next();
          System.out.println(Encrypt(strTarget));
      }
      if (choice == 2) {
          System.out.println("Enter the string you want to decrypt.");
      }
  
  }
  
  private static String Encrypt(String strTarget) {
      // TODO Auto-generated method stub
      int len = strTarget.length()-1;
  
      String destination = "";
  
      for (int i = 0; i&lt;len; i++)
      {
  
          if (strTarget.charAt(i) != ' ')
          {
              char a = strTarget.charAt(i);
              int b = (int) a;
              b = strTarget.charAt(i)-4;
              a = (char) b;
              if ( b&lt;70 &amp;&amp; b&gt;64)
              {
                  b = strTarget.charAt(i)+26;
                  a = (char) b;
  
                  destination += a;
              }
          }
  
  
      }
      return destination; 
  </code></pre>
  
  <p>}
  }</p>
  
  <p>EDIT: Added the full program.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Menu {
  
  public static String strTarget;
  
  public static String destination = "";
  
  public static void main(String[] args) {
  
  
  Scanner in = new Scanner(System.in);
  
  System.out.println("Welcome to the encr/decr program");
  
  System.out.println("To encrypt a string, press 1, to decrypt a string, press 2");
  
  
  
  int choice = in.nextInt();
  
  if (choice == 1) {
      System.out.println("Type the string you want to encrypt.");
  
      strTarget = in.next();
  
      StringBuilder zomg = new StringBuilder(strTarget);
  
      System.out.println(Encrypt(zomg));
  
  
  }
  
  if (choice == 2) {
      System.out.println("Enter the string you want to decrypt.");
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code> private static String Encrypt(StringBuilder zomg) {
  // TODO Auto-generated method stub
  
  int len = strTarget.length()-1;
  
  for (int i = 0; i&lt;len; i++)
  {
  
      if (strTarget.charAt(i) != ' ')
      {
          char a = strTarget.charAt(i);
          int b = (int) a;
          b = strTarget.charAt(i)-4;
          a = (char) b;
          destination += a;
          if ( b&lt;70 &amp;&amp; b&gt;65)
          {
              b = strTarget.charAt(i)+26;
              a = (char) b;
              destination += a;
          }
      }
  
  
  }
  System.out.println(destination);
  return destination; 
  </code></pre>
  
  <p>} }</p>
  
  <p>I made the changes you said (I think), and it start to work, but it isn't working as it is supposed to. Gives some results which do not seem to make sense (for 'A', it return =, for 'V', it returns 'V'). Any suggestions?</p>