/** Methods of the Strings class introduced here:
/*  substring, concat, replace, trim */
import java.util.Scanner;

public class StringsNotModified {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.print("Do you want to run this program?(y/n) ");
    String ans = sc.nextLine();
    ans = ans.trim();
    if (ans.charAt(0)=='N' ||  ans.charAt(0)=='n')
        return;
    
    String fullName = "John Doe";
    String firstName, lastName;
    
    firstName = fullName.substring(0, fullName.indexOf(" "));
    lastName = fullName.substring(fullName.indexOf(" ")+1);
    System.out.println("first name is: " + firstName + "\nLast name is: "
                      + lastName);
    
    String fullNm;
    fullNm = firstName.concat(" ".concat(lastName));
    System.out.println("After concatenating, fullnm is: " + fullNm);
    
    // problem: want to encode a msg
    System.out.println("Enter a msg to be encoded: ");
    String message = sc.nextLine();
    // replace every e with l and every a with c
    String encodedMsg = message.replace('e', 'l');
    encodedMsg = encodedMsg.replace('a', 'c');
    System.out.println("Encoded message is: " + encodedMsg);
    encodedMsg = message;
    for (int i=0; i<message.length(); i++)
        encodedMsg = encodedMsg.replace(message.charAt(i), (char)(message.charAt(i)+2));
    System.out.println("Encoded message is: " + encodedMsg);
      
  }
}