Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unexpected type error

807605Aug 3 2007 — edited Aug 6 2007
Hi, im trying to use the following line of code but it says unexpected type - as far as i can see its a correct type:

in.charAt(i)=(char)(in.charAt(i)+key);

in is a string
key is an int

Whats wrong ?

My full code is :
import java.util.*;
import java.io.*;
public class Encryption
{
    public void encrypt()throws IOException
    {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        System.out.println("Enter a string");
        String in=br.readLine();
        Random randnum = new Random();
        int key = randnum.nextInt(91);
        for (int i=0;i<in.length();i++)
        {
            in.charAt(i)=(char)(in.charAt(i)+key);
               
        }
        System.out.println("Encrypted string is: "+in+"/nKey: "+key);
    }
}
            
        
       
        
            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 3 2007
Added on Aug 3 2007
5 comments
906 views