aspose file tools*
The moose likes Java in General and the fly likes Incorrect output when code syntax seems correct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Incorrect output when code syntax seems correct" Watch "Incorrect output when code syntax seems correct" New topic
Author

Incorrect output when code syntax seems correct

Thomas Crew
Greenhorn

Joined: Nov 13, 2012
Posts: 10
Hi everyone,
I've been working on a java program that decrypts and encrypts Rot-13 messages. The additional requirements for this program are that the program must only encrypt alphabetical letters (leave any other symbols, numbers, characters unchanged) and the methods within this program must be the ones I've used in the following code (along with the same parameters and signatures).
The problem i keep having is that when i run the program, the output is numerical for any character instead of producing the desired Rot-13 decryption. For example: when i input "zzz", the program outputs "109109109". I understand that its some how giving me the decimal number of its character but i don't know how i can fix (this is after 2 days of messing around with the code). I have a feeling the solution is something extremely simple (hopefully). However i'm unable to figure this out on my own at this point. If someone could read over this code and provide me with some kind of help, i would be really grateful :) .

-Thomas



Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

rotateCharacter() returns an int, so you are concatenating a series of ints to the "complete" String.
Thomas Crew
Greenhorn

Joined: Nov 13, 2012
Posts: 10
Greg Charles wrote:rotateCharacter() returns an int, so you are concatenating a series of ints to the "complete" String.


Thanks Greg.

If that's the problem, how would I translate the integers returned by the rotateCharacter() method in decrypt(), so its concatenating the encrypted/decrypted letters along with any unchanged numbers/symbols?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

The method should return a char, not an int. And it should take a char as its parameter too. After all, its job is to turn on char into another char.
Thomas Crew
Greenhorn

Joined: Nov 13, 2012
Posts: 10
Jeff Verdegan wrote:The method should return a char, not an int. And it should take a char as its parameter too. After all, its job is to turn on char into another char.


What would I specifically change in the code. When I change the int parameter to a char the program's output still doesn't work and now I'm noticing that the output is encrypting every character as "109" and adding them to one string. Example: "zz,," = "109109109109"


what i tried doing:


Thomas Crew
Greenhorn

Joined: Nov 13, 2012
Posts: 10
Nevermind with the problem of repeating the first index position (i fixed that). Just still having trouble in figuring out what I specifically should change in the code (in changing the methods parameter from int to char)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Thomas Crew wrote:Nevermind with the problem of repeating the first index position (i fixed that). Just still having trouble in figuring out what I specifically should change in the code (in changing the methods parameter from int to char)


You deleted your code, so I don't know what to tell you other than have the method accept and return a char. You can do math on a char just like on an int. For instance 'D' - 2 gives 'B' (although you'll probably have to cast the result to char).

Take your best shot, and if you get stuck, post your code and ask a specific question about what you're having trouble with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Incorrect output when code syntax seems correct
 
Similar Threads
Desperately Need Help
Problem with char/string representation
Ecryption program question
File encryption / decryption retaining line feeds
Converting string to ASCII values and back