Hi everyone I am new to Java programming...This is a code for ENCRYPTION/DECRYPTION of a message entered by a user program taken from a library book...Here strings "encrypt" and "decrypt" are made to contain char types...It should have been written as "char encrypt=(char)something;" but not as "String encrypt=(char)something;"...But this code works absolutely perfect without compilation error...please help
import java.util.Scanner;
class CaesarsCode
{
public static void main(String[] agrs)
{
Scanner in=new Scanner(System.in);
String encrypt="",decrypt="";
System.out.println("Enter the message to be encrypted:");
String msg=in.nextLine();
for(int i=0;i<msg.length();i++)
{ encrypt+= (char)(msg.charAt(i)+3);//how type-casting allowed here }
System.out.println("Encrypted message : "+encrypt);
for(int i=0;i<msg.length();i++)
{ decrypt+=(char)(encrypt.charAt(i)-3);//how type-casting allowed her }
System.out.println("Decrypted message : "+decrypt);
}
}