Int to Char...I don't know what the problem is here

Everything compiles fine here, and if I print out the "encryption" variable I get what looks like it would be right, converted into chars, but when I try to convert the int to char(my char variable for that is 'w'), my compiler freaks out, I don't even know what it's doing it doesn't give me an error, but sometimes it prints out nothing but sometimes it prints out "puTTypUTtypuTTYPUtty" ...why is it doing that and what is wrong with what I am doing?.
public class encrypt
public static void main(String[] args)
String plainText = "hello, my name is christy.";
String keyWord = "nice to meet you";
int encryption = 0;
char ch = 'a';
char c = 'a';
int encryptor = 0;
int charCode;
int sum = 0;
char w;
int i = plainText.length();
int j = plainText.length();
int[] plain = new int;
int[] key = new int[j];
for(i=0; i<plainText.length(); i++)
ch = plainText.charAt(i);
charCode = (int)ch;
if(charCode > 97 && charCode < 122)//make lowercase
{charCode = charCode - 97;}
if(charCode > 65 && charCode < 90)
{charCode = charCode - 65;}
plain[i] = charCode;
     for(j=0; j<keyWord.length(); j++)
c = keyWord.charAt(j);
int chCode = (int)c;
if(chCode > 97 && chCode < 122)
{chCode = chCode - 97;}
if(chCode > 65 && chCode < 90)
{chCode = chCode - 65;}
key[j] = chCode;
encryption = (plain[i] + key[j]) % 26;
w = (char)encryption;
System.out.print(w);

And for that matter, use increment/decrement assignment operators (like += and -=) instead of verbosely repeating the variable. And if you're going to use character-by-character case conversion, use the methods in Character don't do it like a C programmer circa 1982. And if this is anything other than a homework assignment, use encryption code provided in the JDK; don't reinvent it.

Similar Messages

  • I use MacbookPro late 2011 with Maverick, when i put iPhone 5 or another cellphone askew on left corner of touch pad and slide it to keyboard, the macbook will sleep, i don't know what the problem is, it occur on another macbook pro late 2011

    I use MacbookPro late 2011 with Maverick, when i put iPhone 5 or another cellphone askew on left corner of touch pad and slide it to keyboard, the macbook will sleep, i don't know what the problem is, it occur on another macbook pro late 2011

    It may well be a driver issue but considering the loading: Xorg trying to load different drivers is somewhat normal. @cafe you can see that these are autoconfigured by X above the loading in the log:
    Jul 20 19:48:24 arch gdm-Xorg-:0[216]: (==) Matched intel as autoconfigured driver 0
    Jul 20 19:48:24 arch gdm-Xorg-:0[216]: (==) Matched intel as autoconfigured driver 1
    Jul 20 19:48:24 arch gdm-Xorg-:0[216]: (==) Matched modesetting as autoconfigured driver 2
    Jul 20 19:48:24 arch gdm-Xorg-:0[216]: (==) Matched fbdev as autoconfigured driver 3
    Jul 20 19:48:24 arch gdm-Xorg-:0[216]: (==) Matched vesa as autoconfigured driver 4
    As long as one of the drivers gets loaded, which it apparently does the failing of the others is fine.
    Was there an update maybe ?

  • Every time I sync my iPod Nano (6th gen.) I have to restore it all the time. I don't know what the problem is, I reinstalled my itunes yesterday and it sill does the same thing. Help :(

    As the title says. Everytime I sync my music or my photos into my ipod it keeps asking me to restore it. I don't know what the problem is, I reinstalled my itunes yesterday and it sill does the same thing. My brother told me to visit an Apple store to get help this weekend and I just wanted to ask here first. Help please

    Go to the Apple icon in the upper left corner and select 'About this Mac' - it will show you which version of OSX you are using.
    Read this KB from Apple - http://support.apple.com/kb/ph12113
    MJ

  • Mac Book Air sleeps when moved...i don't know whats the problem...please help me out if anyone knows about this...

    Mac Book Air sleeps when moved...i don't know whats the problem...please help me out if anyone knows about this...

    your reed switch for the monitor is defective, it thinks youve shut the lid when you havent
    mechanical fault , contact Apple for service and parts replacement.

  • I have an ipod touch 4th genereation and have problems when i record you can barley hear the voices and sounds recording i don't know what the problem is?

    i have an ipod touch 4th genereation and have problems when i record you can barley hear the voices and sounds recording i don't know what the problem is?

    sounds like ur ipod's mic is blocked with something check the back on the ipod near the back camera

  • I hope someone knows what the problem is here...

    As of recently my iTunes has been having some problems. I have about 10,000 songs on my iTunes and I have had no problems until the other night when I went to listen to a song (Slap Happy's "Riding Tigers") and it came up as Louden Wainwright's "Swimming Song" and therefore deleting the Slap Happy song. It has been doing this at random from artists as diverse as Mozart to Charlie Parker. I don't know what the problem is and I fear if I continue to explore it myself I may lose half my music library. Also, when I right click a song to "Find" the file it pops up as a completely different song/artist. I don't get it. Can anyone help?

    I'm sure with a collection that large you don't have to be told about proper back ups, it would be disastrous to lose all that music.
    The music is likely still there in iTunes Music but something is corrupting your library data file, the itl.
    What's running on your computer that could do this and did your computer come with any pre-installed media software, Sony Vaios are notorious for causing trouble with their included media management software, or have you installed any desktop search software?
    Lastly, run a malware scan.

  • I turned off my iMessage on my iphone4 and went to turn it back on but it stil saying waiting for activation I have tried everything and don't know what the problem is..what should I do?

    I turned off my iMessage on my iphone4 I tried turning it back on but it won't work it's not letting me turn it back on I have tired everything but nothing will work it keeps saying waiting for activation I don't what the problem is what do I do!

    Currently down:
    http://www.apple.com/support/systemstatus/

  • The video doesn't work in my firefox programme i don't know what the problem is could you help me fix that

    i can't listen to any video though i have the latest version and the latest updates what is the problem then could u help me as quick as possible

    If you're not happy with it and the developer won't give you a refund, give it a bad review in the app store.

  • I get a JavaScript Application error message that appears multiple times on most webpages and I don't know what the problem is.

    Here is the error message:
    [JavaScript Application]
    evalInSandbox:Error: Premission denied for
    <https://www.facebook.com> to create wrapper for
    object of class UnnamedClass
    The message pops up multiple times whenever I reload certain pages.
    The problem does not happen in Safari or Chrome.
    I've restarted Firefox but it does not help.
    Let me know if there is anything I can do to make the error stop.
    Thanks!

    hello flabs, this is likely caused by an outdated extension. in case you have the social fixer addon installed, please update it to the latest version that is available at http://socialfixer.com/blog/category/releasenotes/.

  • Google blogs says that my cookies functionality is turned off, but in the privacy section it says "accept cookies from sites until they expire"--so I don't know what the problem is. is

    When I go to post on a google blog and it asks me to sign in, I get a message that says that my cookies fuctionality is turned off, but when I go to firefox, to preferences and privacy, "accept cookies from sites until they expire" is checked. I don't understand why I am getting this google message which is preventing me from posting, as it seems that the cookies functionality is properly turned on.
    Please advise
    [email protected]

    This is a user-to-user technical support forum. Apple is not here. You can find contact information from Apple by using the Contact Us link at the bottom right of every page.
    iPhones do not have international warranties. The only place in which you can get Apple service on your phones would be Hong Kong. Unless you have AppleCare, neither of these phones is under warranty. It is likely that the best Apple could offer you is an out-of-warranty replacement.

  • TS4062 i have 16 songs that did not download to my iphone, don't know what the problem is--have several songs that did download, am i doing something wrong?

    i have 16 songs that won't download to my iphone. i have several songs that did go thru. Am i doing something wrong.

    tis true
    I know, I always do that but I was in a rush to get somewhere and I was relying on my thousand dollar Mac to do some kind of recovery or something. I know Microsoft always keeps temporary files (I think Mac does too, part of me asking here in this forum was for someone to tell me where I can find those files) and when you go to open Office Works then it gives you the option of opening the last recent documents, saved or not saved.
    I usually copy paste into my emial just in case something goes wrong with the created document but I just didn't have the time to login and do all that My loss, you live and you learn, BUT still if ANYONE got any info on this, PLEASE DO CHIME IN *keeping the hope alive*

  • I have never dropped my iPhone and when I try to take a video on my phone there is no sound and if I send it to someone they can't hear it either I don't know what the problem Is but will apple replace that? Or will it cost some money to fix it?

    I have never dropped my iPhone before and when I take a video and or send it to a friend they can't hear it and either can I. I was wondering if apple would replace it by sending me a new iPhone or if it would cost money to fix?

    You can message them in the chat click on this link http://store.apple.com/us/search/chat-support then click on Chat Now next to the blue bubble

  • HT4060 Hello, I just got an ipad2 and i hae gone through seven chargers. I don't know what the problem is, any suggestions

    I Got an ipad2 not to long ago an pd I have had to go through seven chargers already, can someon eplease explain why this keeps happening?

    Could be the device also may bear inspection and testing, in case
    that may need replacement; there is a chance it may contribute to
    the failure rate you have experienced among power supplies.
    If the electrical mains and plugs in the location the device is used
    are tested OK, and if you've tried using an automatic self-regulating
    uninterruptible power supply (with its own backup battery) to stop
    any effects of spike, surge, or quick fluctuation of voltage, the next
    item to look into may be to see if the device itself places undue load
    on the power supplies.
    Maybe you should ask about this aspect of your experience.
    Good luck & happy computing!

  • I don't know whats the problem can anyone plz assist me

    Dear friends
    I have two servers one for application and other for oracle. Yesterday we changed the domain of database server and then on application is not connecting with oracle database. we can ping and share files from both servers. Also modified application settings in web server to match new configuration.
    And another thing i can't connect with sys as sysdba it shows insufficient privillege error and in the application it shows ora-12638 credential retrieval failed so please anyone help me it is very urgent..

    C:\Documents and Settings\RSalha>sqlplus
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue Sep 15 10:17:28 2009
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Enter user-name: sys as sysdba
    Enter password:
    ERROR:
    ORA-01031: insufficient privileges
    Listener.ora_
    # listener.ora Network Configuration File: D:\oracle\product\10.2.0\db_2\network\admin\listener.ora
    # Generated by Oracle configuration tools.
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = orcl)
    (ORACLE_HOME = D:\oracle\product\10.2.0\db_2)
    (PROGRAM = extproc)
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = IMEORCL)(PORT = 1521))
    TNSNAME.ORA_
    # tnsnames.ora Network Configuration File: D:\oracle\product\10.2.0\db_2\network\admin\tnsnames.ora
    # Generated by Oracle configuration tools.
    ORCL =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.10)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ORCL)
    EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
    (CONNECT_DATA =
    (SID = PLSExtProc)
    (PRESENTATION = RO)
    )

  • TS4559 I don't know if this was already asked, but every time I put my headphones on my iMac OSX (2007 version) I always hear it on a different output then my headphones. But they worked last time...  I just don't know what the problem is...

    It just happen to me today... while I was listening to music it went to a different output. But strangely... it works on my ipad 2 wifi.
    If this happen to you PLEASE reply. Thank You.

    Hello pagtaljav1,
    It sounds like you're not hearing audio from you headphones when connected to your iMac.  You may want to check the output settings in System Preferences.  You can find the steps to do this in this article:
    OS X Mountain Lion: Change your computer’s sound output device
    http://support.apple.com/kb/PH11235
    If the setting is correct there, and you are still not getting audio from the headphones, I recommend resetting the NVRAM / PRAM:
    About NVRAM and PRAM
    http://support.apple.com/kb/HT1379
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

Maybe you are looking for

  • Using AppleScript to sort files Into Specified Folders based on Extension

    Hi All! Here is what I am trying to figure out. I would love some help with this script if anyone can lend a helping hand. I am currently using Hazel to do this but I think AppleScript will be alot more effective. Situation: - I have a folder with 4

  • Color Bars and tone in FCP X?

    Just downloaded FC"P" X and having a look around I cant find Color Bars or Tone anywhere...? Did a quick search on the help... but couldn't find anything. Surely I must be missing something here - they must be available right!!? I know I could output

  • "USE flags" for makepkg

    I have an idea for makepkg, but I wanted to discuss it before I file a feature request on flyspry. The idea is similar to Gentoo's USE flags, but don't let this pollude your opinion if you dislike Gentoo. The idea goes like this. In some config file,

  • Ipod photo - serious music transfer probleme. i need help please

    hi there. i have a problem that i cant resolve. i search and ask on french forum, but nobody could help me. actually, my ipod didnt want me to upload files over 6 minutes. an error message box used to pop up on itunes each time the delay of about 6 m

  • Boot Camp Manager ERROR message

    Everytime i go into Bootcamp, Bootcamp Manager error comes up "Bootcamp manager has encounted a problem and need to close we are sorry for the inconvenience" I sended the error report several times, but no solution. I have re-installed the windows an