Incrementing every letter in a string that occupies an odd position.

Hi, for an "encryption" project, i need your help creating a method that will be incrementing by 5 every char in a string that occupies an odd position in that same string.
For example : 'adam' should return 'aiar'
-Method can't use arrays.
-Method can't use regular expressions like 'split' etc..in order words the teacher wants us to use the simplest stuff inside the String class.
-Only letters must be modified.
so far i have this : (names of values are in french, sorry)
public class Main {
public static String incrementerDeCinqImpaires (String chaine) {
char j = chaine.charAt(1);
char x = chaine.charAt(3);
char o = chaine.charAt(5);
j+=5;
x+=5;
o+=5;
System.out.println(x);
System.out.println(j);
System.out.println(o);
String   tmpString = chaine.replace( chaine.charAt(1), j );
String   tmpString2 = tmpString.replace( tmpString.charAt(3), x );
String   tmpString3 = tmpString2.replace( tmpString2.charAt(5), o );
System.out.println( "Original = " + chaine );
System.out.println( "Result   = " + tmpString3 );
return tmpString3;
public static void main (String args [] ) {
       System.out.println (incrementerDeCinqImpaires("adam"));
}The thing is i need a "for" loop (which has been a nightmare for me trying to figure out how to make it) in order to increment every odd positioned char in the string.
So all I need really is to sum up what i posted above inside a for loop (or more). Then just add ifs and elses so i can increment only letters.

I don't think String.replace will do what you want. What happens when a single letter appears in an even-numbered position and then in a later odd-numbered position?
Can you use StringBuilder?
Or you can do a bunch of String appends (i.e., use StringBuilder implicitly), one character at a time, in a loop.
By the way you haven't done the part where you check that the character is a letter.
Also, what do you do with the last five letters of the alphabet? (Regardless of the alphabet you're using.) You could end up inserting control characters or characters that you can't print in your locale. Do you wrap?

Similar Messages

  • Deleting the Records that are in odd position

    Hi,
       How to delete the records that are in the odd position.
    This is my program. Plz correct me. Iam not able to delete the records.
    REPORT  ZMTSHPRG19                              .
    TYPES:
    BEGIN OF TY_EMP,
    EMPID(4) TYPE N,
    ENAME(30) TYPE C,
    DEPT(4) TYPE C,
    SALARY TYPE I,
    END OF TY_EMP.
    DATA:
    FS_EMP TYPE TY_EMP,
    IT_EMP TYPE TABLE OF TY_EMP.
    FS_EMP-EMPID = '1009'.
    FS_EMP-ENAME = 'XX'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = '1007'.
    FS_EMP-ENAME = 'YY'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = '11000'.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1008.
    FS_EMP-ENAME = 'ZZ'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1001.
    FS_EMP-ENAME = 'XY'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1003.
    FS_EMP-ENAME = 'XZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 8000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1002.
    FS_EMP-ENAME = 'YX'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1004.
    FS_EMP-ENAME = 'YZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1005.
    FS_EMP-ENAME = 'AA'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1006.
    FS_EMP-ENAME = 'BB'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1010.
    FS_EMP-ENAME = 'CC'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 15000.
    APPEND FS_EMP TO IT_EMP.
    LOOP AT IT_EMP INTO FS_EMP.
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    ENDLOOP.
    ULINE.
    DATA:
    LINE_COUNT TYPE I,
    W_REM TYPE I.
    W_REM = LINE_COUNT MOD 2.
    DESCRIBE TABLE IT_EMP LINES LINE_COUNT.
    SORT IT_EMP BY EMPID.
    IF W_REM = 0.
    LOOP AT IT_EMP INTO FS_EMP.
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY..
    ENDLOOP.
    ENDIF.
    Thanks.

    TYPES:
    BEGIN OF TY_EMP,
    EMPID(4) TYPE N,
    ENAME(30) TYPE C,
    DEPT(4) TYPE C,
    SALARY TYPE I,
    END OF TY_EMP.
    DATA:
    FS_EMP TYPE TY_EMP,
    IT_EMP TYPE TABLE OF TY_EMP.
    FS_EMP-EMPID = '1009'.
    FS_EMP-ENAME = 'XX'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = '1007'.
    FS_EMP-ENAME = 'YY'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = '11000'.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1008.
    FS_EMP-ENAME = 'ZZ'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1001.
    FS_EMP-ENAME = 'XY'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 10000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1003.
    FS_EMP-ENAME = 'XZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 8000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1002.
    FS_EMP-ENAME = 'YX'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1004.
    FS_EMP-ENAME = 'YZ'.
    FS_EMP-DEPT = 'D300'.
    FS_EMP-SALARY = 9500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1005.
    FS_EMP-ENAME = 'AA'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 10500.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1006.
    FS_EMP-ENAME = 'BB'.
    FS_EMP-DEPT = 'D200'.
    FS_EMP-SALARY = 12000.
    APPEND FS_EMP TO IT_EMP.
    FS_EMP-EMPID = 1010.
    FS_EMP-ENAME = 'CC'.
    FS_EMP-DEPT = 'D100'.
    FS_EMP-SALARY = 15000.
    APPEND FS_EMP TO IT_EMP.
    LOOP AT IT_EMP INTO FS_EMP.
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    ENDLOOP.
    ULINE.
    DATA:
    LINE_COUNT TYPE I,
    W_REM TYPE I,
    n type i value 1.
    DESCRIBE TABLE IT_EMP LINES LINE_COUNT.
    SORT IT_EMP BY EMPID.
    LOOP AT IT_EMP INTO FS_EMP.
    w_rem = n mod 2 .
    if w_rem = 0 .
    WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-SALARY.
    endif.
    n = n + 1.
    ENDLOOP.
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Apr 11, 2008 4:34 PM

  • Bridge will not now let me use camera raw, though I had been using it every day.  It says that "the parent application is not active.  Bridge requires that a qualifiying product has  been launched at least once to enable this feature."  What am I to do?

    Bridge will not now let me use camera raw, though I have been using it every day.  It ways that "the parent application is not active.  Bridge requires that a qualifiying product has  been launched at least once to enable this feature."  What am I to do?

    Usually this points to having some kind of earlier trial version still installed on your system. However without more details you are not likely to find an answer. Try this for a start:
    How To Get Help Quickly

  • My ipod touch is all of a sudden not letting me do anything that requires my password. I can buy apps or anything. I put in my password and it gives me an error and says try again later. It works fine if I am accessing the store thru my computer. Help?

    My ipod touch is all of a sudden not letting me do anything that requires using my password. I can't buy anything and I can't check my purchases. Every time I put in my password I get an error message and it says try again later. This has been happening for 4 days now. I can play my existing games just fine. I can access my itunes store through the internet just fine with my password, but just not on my ipod touch. I sent an email to the itunes support store 3 days ago and have not heard back from them. Does anybody have any suggestions on why this is happening all of a sudden after having the ipod for almost 2 years?

    Something you can try is resetting it all Settings > General > Reset > Reset all settings. Or go to Settings > Store &amp; sign out &amp; log back in. Another thing you can do is restore your ipod. This has happened to me but the only thing i did was that i created a new account but try doing the things above i just told you. :)

  • Servermgrd[584]: FIXME: IOUnserialize has detected a string that is not valid UTF-8, "v\035\363d".

    All,
    I am having a very odd problem.
    I have recently setup a Mac OS X Mavericks Server for the purposes of NetRestore.
    Everything setup fine, no issues whatsoever and the server has been running non-stop for the past 78 days.
    I've already imaged about 100 MacBook pros off of this server without a problem.
    This morning I come in, start up an MBP that needs to be imaged and it sees the netrestore volumes and attemps to boot to it
    then stops and doesn't go anywhere.
    I've had my NBI's on an external firewire 800 drive (1TB Lacie Rugged) and its been working fine.
    I've checked my logs numerous times and the only error I can find is: servermgrd[584]: FIXME: IOUnserialize has detected a string that is not valid UTF-8, "v\035\363d".
    The exact same error keeps repeating every 10 seconds or so.
    I read in another forum that sometime Mavericks Server doesn't like NBI images on external volumes, so I moved them to the standard /Library/Netboot/NetBootSP0 folder on the boot volume and turned off the external drive.
    I'm able to NetRestore again now, but the process is far slower then it was previsously and the error above still persists.
    I've rebooted the server, stopped and restarted the services, made sure no changes have been made on the network, and fully updated the server via software update.
    Any ideas would be greatly appreciated!
    Thanks in advance.

    I post some other error.
    I don't understand why some times when I reboot I don't get any errors and why some Ive this:
    Mac OS X Versione 10.4.9 (Build 8P2137)
    2007-04-26 09:26:54 +0200
    At revision 7057.
    Apr 26 09:27:02 MacBook diskarbitrationd[49]: SystemUIServer [265]:15143 not responding.
    Apr 26 09:27:02 MacBook /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framewo rk/Support/ATSServer: FIXME: IOUnserialize has detected a string that is not valid UTF-8, "ˆ®˜Ëî^?Ío".
    Can any help me to found the problem???????
    Thanks so much to all

  • How to read each and every word from a string.

    Hi all,
       I have a string which is having many label numbers. if the string is lv_str, its value is like, 11111111111111##22222222222222##3333333333333.
    I need to move the values alone into internal table. each value should be updated as a single row into one internal table. How to read each and every word of the string and move to an internal table.
    the internal table should be like this.
    11111111111111
    22222222222222
    3333333333333
    Can any one give me a suggestion in this regard.
    POINTS PROMISED.
    Regards,
    Buvana

    Hi,
    If you know the format and length of the data
    Use split at '#' so that you will get the individual values.
    Thean append it to internal table.
    Reward iof helpful.

  • Read every character in a string

    Hi,
    I want to read every charater in a string and if I find a special character(¿) then want to replace with replace it with(°) symbol. length of the characters are not fixed.
    Please advise.
    Regards,
    Arnie.

    user558927 wrote:
    Hi,
    I want to read every charater in a string and if I find a special character(¿) then want to replace with replace it with(°) symbol. length of the characters are not fixed.
    Please advise.
    Regards,
    Arnie.There's built in functionality for that.
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions153.htm#SQLRF00697
    Cheers,

  • Voice over every word instead of every letter

    Is there a way to set voiceover to automatically read every 'word' while typing, maybe using the spacebar as a trigger, as opposed to reading every 'letter' as typed?
    I've tried everything and this would be golden for me.

    Yes, you can do this. Here are the instructions. http://help.apple.com/imovie/#mov3b0fb060
    In your case, make sure that no individual clip is selected (highlighted in yellow) before you start the voiceover.

  • I am trying to add a game to my sons I touch pad. It is a free game. It asks for verification of password and credit card info. Every time, it tells me that my time has expired. Help.

    I am trying to add a game to my sons I touch pad. It is a free game. It asks for verification of password and credit card info. Every time, it tells me that my time has expired. Help.

    It asked me that too.Don't worry and just put it in. Itunes doesn't charge unless your son buys something. The password happens to me all the time. Credit card was only once. Just make sure your son knows not to buy anything without permission so he doesn't accidently charge you something.

  • Pages will no longer let me open files that I have previously downloaded, worked on and then saved on my mac. However it will let me open pages documents that I have started from new. I need the other documents to open and can't figure it out. PLEASE

    Pages will no longer let me open files that I have previously downloaded, worked on and then saved on my mac. However it will let me open pages documents that I have started from new. I need the other documents to open and can't figure it out. PLEASE

    I just got my mac a month ago so go easy on me but I was just working with the pages that was already on it, and then today I know it updated, and now I am unable to open a lot of my documents!:(  Idk what you mean by the icloud version lol sorry! As for the version, when I open pages from my apps and click 'about' it says version 5.1? And when I open the document it just goes grey and kind of blinks and doesnt open? No error message or any indication of why it will not open now when I for sure have opened it in the past! Andddd for the OS X I think it is 10.9.1 ??

  • Please help block my ipod touch second generation and forget the code, try putting the code so many times that now says connect to itunes, I connect but will not let me do anything that tells me this should unlock with key and I should do for Please help!

    please helpme i block my ipod touch second generation and forget the code, try putting the code so many times that now says connect to itunes, I connect but will not let me do anything that tells me this  should unlock with key and I should do for Please help!. thanks

    Place the iPOd in recovery mode and then restore. For recovery mode:
    iPhone and iPod touch: Unable to update or restore

  • When trying to import photos with iPhoto from photoshop.. won't let me keeps saying that the photos are already in the iPhoto library but they are not... need to fix this

    When trying to import photos with iPhoto from photoshop... won't let me keeps saying that the photos are already in the iPhoto library but they are not

    If you are using Photoshop from within iPhoto the following may help with the workflow.  However, we do need to know the answers to the questions posed by Terence and Larry to be able to help you.
    Using Photoshop or Photoshop Elements as Your Editor of Choice in iPhoto.
    1 - select Photoshop or Photoshop Elememts as your editor of choice in iPhoto's General Preference Section's under the "Edit photo:" menu.
    2 - double click on the thumbnail in iPhoto to open it in Photoshop.  When you're finished editing click on the Save button. If you immediately get the JPEG Options window make your selection (Baseline standard seems to be the most compatible jpeg format) and click on the OK button. Your done.
    3 - however, if you get the navigation window
    that indicates that  PS wants to save it as a PS formatted file.  You'll need to either select JPEG from the menu and save (top image) or click on the desktop in the Navigation window (bottom image) and save it to the desktop for importing as a new photo.
    This method will let iPhoto know that the photo has been editied and will update the thumbnail file to reflect the edit..
    With Photoshop Elements  the Saving File preferences should be configured as shown:
    I also suggest the Maximize PSD File Compatabilty be set to Always.  In PSE’s General preference pane set the Color Picker to Apple as shown:
    Screenshots are from PSE 10
    Note 1:  to switch between iPhoto and PS or PSE as the editor of choice Control (right)-click on the thumbnail and select either Edit in iPhoto or Edit in External Editor from the contextual menu. If you use iPhoto to edit more than PSE re-select iPhoto in the iPhoto General preference pane. Then iPhoto will be the default editor and you can use the contextual menu to select PSE for your editor when desired.
    Note 2:  editing a RAW file with either PSE or PS creates a new file which must be saved outside of iPhoto, i.e. the Desktop, and imported as a new photo into the iPhoto Library.

  • I went on my MacBook Pro this morning and found out that my Macbook Pro isnt charging, is the power adapter damaged? Or is it the power adapter string that attatches to the Macbook Pro?

    I dont know what is wrong with my computer,if is it because there is something wrong with my MacBook Pro or if its the actual power adapter or the string that attatches the power adapter and the computer. HELP PLEASE!!!

    Have you tried to do an SMC/PRAM reset?
    Also, need to know how old your MB Pro is.

  • Dynamically Setting a Variable from a Connection String that has been set by a Config File

    Hi Guys
    I'm setting up a Master / Slave (Parent / Child) dtsx environment but I'm unable to work out how to dynamically set a variable in the Master dtsx from a connection string that has had its value set by a config file. I'm sure it's possible.
    Below is the what I'm hoping to achieve. I've set up everything apart from the highlighted section.
    Any ideas?

    First, what version of SQL Server are you using?
    You could switch the problem around.  You could set the value of a variable from the config file, then it is easy to use that variable as the connection string source for your connection manager.  At the same time you can use a parent variable
    configuration to map that variable to variables in your child package.
    Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

  • I use an Apple bluetooth keyboard with my iPad. In messages I can't find a way to "send" a message without tapping on Send on the iPad's screen. I've tried every key and key combo that I can think of. Am I missing something?

    I use an Apple bluetooth keyboard with my iPad. In messages I can't find a way to "send" a message without tapping on Send on the iPad's screen. I've tried every key and key combo that I can think of. Am I missing something?

    I already have multiple devices and by far I like my iPad the most over laptops and the iPad. That including checking out my friends MacBook Air.
    The difference for me is the touch interface on the screen itself for things that do not require a lot of typing. For me, the iPad is more "magical" than anything else I've used.
    Again, I do appreciate your answers but you don't know my situation. Not everything is as it is perceived without knowing me and what I have to go through.

Maybe you are looking for

  • Moving multiple events to a new HD

    I have a new external HD. I'm wanting to move many, many events from one external HD to the new one. Seems I can only move one event at a time. If I Command Click to select multiple events then Command and drag, that is not possible. If I click an ev

  • Saving photo attachments from Mail to iPhone

    Merry Christmas The MMS debate and iPhone rages on and many iPhone fanatics say 'why do you need MMS when you can send/receive photos as email attachments...?'. If that's the case, is there any way you can save a photo received as an email attachment

  • I'd like a new iPod Classic model

    Is it really too much to ask for one with a larger SSD drive and possibly wireless sync capabilities?  Admittedly, since I got a Sonos the iPod has been relegated to the office but I still use it most days.  What else would you like?

  • Error in IDOC segment

    Hi guys I have a problem here with IDOCs. I am getting this nasty entry in a field of a segment of my message type. Because of that entry my IDOC is failing but at the same time there are similiar IDOCs with everything same and they are posted OK. I

  • Event handling to the drop down list in the web dypro ALV.

    Hi Experts, In my dynpro ALV i have 5 fields. in that 2ed field has the drop down list. if i select any of from the list, based on the particular selected value, some value should be reflect in the 3rd field of the ALV. Ex: dropdown list of  2ed fiel