Given a String, return an array of char values that contains the characters of the string in reverse order...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-3















From the title you can see what I'm trying to do, however it's not working and I'm not sure why. Who has any ideas or simpler way to do this method?
(without using string builder and all that extra stuff)



public char reverseStringToArray(String str)
{

char reverseStringToArray = str.toCharArray();

char characters = new char[reverseStringToArray.length];

for (int i = reverseStringToArray.length - 1; i >= 0; i--)

characters[i] = reverseStringToArray[i];

return reverseStringToArray;
}









share|improve this question















closed as off-topic by Hovercraft Full Of Eels, cнŝdk, Unheilig, EdChum, aaaaaa123456789 Nov 22 '18 at 9:59


This question appears to be off-topic. The users who voted to close gave these specific reasons:



  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Unheilig, aaaaaa123456789

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Hovercraft Full Of Eels, cнŝdk, EdChum


If this question can be reworded to fit the rules in the help center, please edit the question.












  • 2





    Here characters[i] = reverseStringToArray[i]; those indices should be different. I'll leave it to you to figure out what they should be, but it's very simple math.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 4





    Also this return reverseStringToArray[i]; shouldn't compile!

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 2





    Side question -- why are you using Character and not char? A Character array is not the same as a char array.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:40




















-3















From the title you can see what I'm trying to do, however it's not working and I'm not sure why. Who has any ideas or simpler way to do this method?
(without using string builder and all that extra stuff)



public char reverseStringToArray(String str)
{

char reverseStringToArray = str.toCharArray();

char characters = new char[reverseStringToArray.length];

for (int i = reverseStringToArray.length - 1; i >= 0; i--)

characters[i] = reverseStringToArray[i];

return reverseStringToArray;
}









share|improve this question















closed as off-topic by Hovercraft Full Of Eels, cнŝdk, Unheilig, EdChum, aaaaaa123456789 Nov 22 '18 at 9:59


This question appears to be off-topic. The users who voted to close gave these specific reasons:



  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Unheilig, aaaaaa123456789

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Hovercraft Full Of Eels, cнŝdk, EdChum


If this question can be reworded to fit the rules in the help center, please edit the question.












  • 2





    Here characters[i] = reverseStringToArray[i]; those indices should be different. I'll leave it to you to figure out what they should be, but it's very simple math.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 4





    Also this return reverseStringToArray[i]; shouldn't compile!

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 2





    Side question -- why are you using Character and not char? A Character array is not the same as a char array.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:40
















-3












-3








-3


1






From the title you can see what I'm trying to do, however it's not working and I'm not sure why. Who has any ideas or simpler way to do this method?
(without using string builder and all that extra stuff)



public char reverseStringToArray(String str)
{

char reverseStringToArray = str.toCharArray();

char characters = new char[reverseStringToArray.length];

for (int i = reverseStringToArray.length - 1; i >= 0; i--)

characters[i] = reverseStringToArray[i];

return reverseStringToArray;
}









share|improve this question
















From the title you can see what I'm trying to do, however it's not working and I'm not sure why. Who has any ideas or simpler way to do this method?
(without using string builder and all that extra stuff)



public char reverseStringToArray(String str)
{

char reverseStringToArray = str.toCharArray();

char characters = new char[reverseStringToArray.length];

for (int i = reverseStringToArray.length - 1; i >= 0; i--)

characters[i] = reverseStringToArray[i];

return reverseStringToArray;
}






java arrays string loops char






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 1:56







whose mans is this

















asked Nov 22 '18 at 1:38









whose mans is thiswhose mans is this

11




11




closed as off-topic by Hovercraft Full Of Eels, cнŝdk, Unheilig, EdChum, aaaaaa123456789 Nov 22 '18 at 9:59


This question appears to be off-topic. The users who voted to close gave these specific reasons:



  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Unheilig, aaaaaa123456789

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Hovercraft Full Of Eels, cнŝdk, EdChum


If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Hovercraft Full Of Eels, cнŝdk, Unheilig, EdChum, aaaaaa123456789 Nov 22 '18 at 9:59


This question appears to be off-topic. The users who voted to close gave these specific reasons:



  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Unheilig, aaaaaa123456789

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Hovercraft Full Of Eels, cнŝdk, EdChum


If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2





    Here characters[i] = reverseStringToArray[i]; those indices should be different. I'll leave it to you to figure out what they should be, but it's very simple math.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 4





    Also this return reverseStringToArray[i]; shouldn't compile!

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 2





    Side question -- why are you using Character and not char? A Character array is not the same as a char array.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:40
















  • 2





    Here characters[i] = reverseStringToArray[i]; those indices should be different. I'll leave it to you to figure out what they should be, but it's very simple math.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 4





    Also this return reverseStringToArray[i]; shouldn't compile!

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:39






  • 2





    Side question -- why are you using Character and not char? A Character array is not the same as a char array.

    – Hovercraft Full Of Eels
    Nov 22 '18 at 1:40










2




2





Here characters[i] = reverseStringToArray[i]; those indices should be different. I'll leave it to you to figure out what they should be, but it's very simple math.

– Hovercraft Full Of Eels
Nov 22 '18 at 1:39





Here characters[i] = reverseStringToArray[i]; those indices should be different. I'll leave it to you to figure out what they should be, but it's very simple math.

– Hovercraft Full Of Eels
Nov 22 '18 at 1:39




4




4





Also this return reverseStringToArray[i]; shouldn't compile!

– Hovercraft Full Of Eels
Nov 22 '18 at 1:39





Also this return reverseStringToArray[i]; shouldn't compile!

– Hovercraft Full Of Eels
Nov 22 '18 at 1:39




2




2





Side question -- why are you using Character and not char? A Character array is not the same as a char array.

– Hovercraft Full Of Eels
Nov 22 '18 at 1:40







Side question -- why are you using Character and not char? A Character array is not the same as a char array.

– Hovercraft Full Of Eels
Nov 22 '18 at 1:40














1 Answer
1






active

oldest

votes


















2














StringBuilder has a useful method reverse(), you can use that and then convert to a char. Like,



return new StringBuilder(str).reverse().toString().toCharArray();


If you must implement your own array reverse here, it's important to know not to reverse elements beyond the half-way mark (why? because you will reverse them and then reverse them back). Note that you also need to perform a full swap or you'll lose half of your input. That is, it should look something like,



char rsa = str.toCharArray();
for (int i = 0; i < rsa.length / 2; i++) {
char ch = rsa[i];
rsa[i] = rsa[rsa.length - i - 1];
rsa[rsa.length - i - 1] = ch;
}
return rsa;





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    StringBuilder has a useful method reverse(), you can use that and then convert to a char. Like,



    return new StringBuilder(str).reverse().toString().toCharArray();


    If you must implement your own array reverse here, it's important to know not to reverse elements beyond the half-way mark (why? because you will reverse them and then reverse them back). Note that you also need to perform a full swap or you'll lose half of your input. That is, it should look something like,



    char rsa = str.toCharArray();
    for (int i = 0; i < rsa.length / 2; i++) {
    char ch = rsa[i];
    rsa[i] = rsa[rsa.length - i - 1];
    rsa[rsa.length - i - 1] = ch;
    }
    return rsa;





    share|improve this answer






























      2














      StringBuilder has a useful method reverse(), you can use that and then convert to a char. Like,



      return new StringBuilder(str).reverse().toString().toCharArray();


      If you must implement your own array reverse here, it's important to know not to reverse elements beyond the half-way mark (why? because you will reverse them and then reverse them back). Note that you also need to perform a full swap or you'll lose half of your input. That is, it should look something like,



      char rsa = str.toCharArray();
      for (int i = 0; i < rsa.length / 2; i++) {
      char ch = rsa[i];
      rsa[i] = rsa[rsa.length - i - 1];
      rsa[rsa.length - i - 1] = ch;
      }
      return rsa;





      share|improve this answer




























        2












        2








        2







        StringBuilder has a useful method reverse(), you can use that and then convert to a char. Like,



        return new StringBuilder(str).reverse().toString().toCharArray();


        If you must implement your own array reverse here, it's important to know not to reverse elements beyond the half-way mark (why? because you will reverse them and then reverse them back). Note that you also need to perform a full swap or you'll lose half of your input. That is, it should look something like,



        char rsa = str.toCharArray();
        for (int i = 0; i < rsa.length / 2; i++) {
        char ch = rsa[i];
        rsa[i] = rsa[rsa.length - i - 1];
        rsa[rsa.length - i - 1] = ch;
        }
        return rsa;





        share|improve this answer















        StringBuilder has a useful method reverse(), you can use that and then convert to a char. Like,



        return new StringBuilder(str).reverse().toString().toCharArray();


        If you must implement your own array reverse here, it's important to know not to reverse elements beyond the half-way mark (why? because you will reverse them and then reverse them back). Note that you also need to perform a full swap or you'll lose half of your input. That is, it should look something like,



        char rsa = str.toCharArray();
        for (int i = 0; i < rsa.length / 2; i++) {
        char ch = rsa[i];
        rsa[i] = rsa[rsa.length - i - 1];
        rsa[rsa.length - i - 1] = ch;
        }
        return rsa;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 1:54

























        answered Nov 22 '18 at 1:43









        Elliott FrischElliott Frisch

        156k1396191




        156k1396191

















            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?