java - Subtract int from char : possible lossy conversion int to char -


i trying subtract int char in typical cryptography key question running above mentioned error in following statements:

char ch = (int)encrypted_message.charat(i) + key[index]; if (ch > 122)     ch = (int)ch - 26; 

key[] array holds digits of key , of type int.

how rotate char successfully?

please help!

int bigger char, result of operation typed int (which you're storing in char). compiler warning you might lose information storing int value char variable.

instead, ensure result char, bit of pain because + , - char values results in int, have cast:

char ch = (char)(encrypted_message.charat(i) + key[index]); if (ch > 122)     ch = (char)(ch - 26); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -