• Post Reply Bookmark Topic Watch Topic
  • New Topic

Caesar Cipher  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We were practicing with Caesar Cipher in my Java class, and my TA didn't have a chance to look at mine and help me fix the problem on it. She told me I was close but didn't have a chance to come back and finish. I'm guessing that we're going to need to have a good understanding of it for our upcoming final, and I would be greatful if I someone could help me figure out what is wrong. I know I get an error with my "letter" variable when I compile, but could not figure out why. Any advice would be appreciated.

 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this line, you are trying to read a String into a String array. You can only read a String into a String. Java is not C.



You also have to consider what device you're trying to read from. Do you need an import statement? Do you need a device object?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, it would help if you could post the exact error message you get when you compile, and indicate the line where the error is on.
 
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to change your input to remove the []'s, both in the declaration (String input; instead of String input[];) and where you use it (input = Console.in.readLine();).

As far as the error on letter, you are probably receiving a "letter may not have been initialized" error. You need to move the char code = caesarCipher(letter,num); line inside the for loop.

Now, that will give you another error on line 14, as it will not recognize the "code" variable. You probably want to use a StringBuffer and build up the encoded string as you loop through the loop and the print the resulting string. I'll leave that as an exercise to the reader (hint: look at the java docs for StringBuffer, especially the .append() method).

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!