How bring back white space from char array to String in java?

Annas Casmawan Ahmad :

I tried to bring back removed white space after encrypted string.

Enter Plain Text:hello world
Result : itssgvgkbsr

It should bring back the removed spaces into their actual places.Expected Output:

Result : itssg gkbsr

  private static void EncryptionChiper(String plainText, String keyChiper){
    char[] letter = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'r', 'x', 'y', 'z'};
    char[] charKeyChiper = keyChiper.toCharArray();
    System.out.print("Result : ");
    for (int i = 0;i<plainText.length();i++){
        for (int j = 0;j<letter.length;j++){
            if(letter[j]==(plainText.charAt(i))){
                System.out.print(charKeyChiper[j]);

            }
        }
    }
}

 System.out.print("Enter Plain Text:");String plainText = scan.nextLine();
 System.out.print("Enter Key(26):");String key = scan.nextLine();
 EncryptionChiper(plainText,key);
Frighi :

Just add another if case:

if(' '==(plainText.charAt(i))){
   System.out.print(' ');
   break;
} else if(letter[j]==(plainText.charAt(i))){
   System.out.print(charKeyChiper[j]);
   break;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=237942&siteId=1