How to reverse a String in java using recursion?

Поділитися
Вставка
  • Опубліковано 28 жов 2024

КОМЕНТАРІ • 26

  • @solnamgung9760
    @solnamgung9760 2 роки тому +3

    amazing ! thanks for your thorough explanations

  • @chandanrout29
    @chandanrout29 3 роки тому +4

    u have not executed remaining iterations , simply escaped. when the method will exactly returned the reversed string to main method. the break point is may be the 1st condition , one time string will become null and it will return, but if string will become null then how it will hold the reversed string.

  • @friendlychannel100
    @friendlychannel100 2 роки тому +1

    It would be better to do it using tail recursion as this recursion has pending operations. We might also get stackoverflow again if the length of string is huge.

  • @naveenkumarkota2090
    @naveenkumarkota2090 Рік тому +1

    understtod tq u

  • @mohanamahamohana2272
    @mohanamahamohana2272 Рік тому

    Clear explanation sir

  • @sucharithaguddam4936
    @sucharithaguddam4936 3 роки тому

    Good explanation. Thank you sir...🙏

  • @adithiatirtazulfikar4567
    @adithiatirtazulfikar4567 3 роки тому +1

    Thank you

  • @prajaktakale1291
    @prajaktakale1291 4 роки тому

    Why we take private static class?can we take public method

    • @kartikn1619
      @kartikn1619 4 роки тому +1

      Yes you can take public method , private method ensures that method is not overridden.

  • @indiantourism975
    @indiantourism975 3 роки тому

    Excellent sir

  • @snehaldas5893
    @snehaldas5893 3 роки тому +2

    im sure you're a school teacher sir

  • @aqibehassan8116
    @aqibehassan8116 4 роки тому +1

    Thanks alot

  • @sagarr.gs.m.s42
    @sagarr.gs.m.s42 4 роки тому

    Really helpful video sir

  • @sagargupta1496
    @sagargupta1496 4 роки тому +1

    Sir program is giving stack overflow error.
    Please correct me if there is any mistake in the code.
    I am having interview tomorrow..please reply early
    public class HelloWorld
    {
    public static void main(String []args)
    {
    String s= "Sandy";
    System.out.println(recursiveString(s));
    }
    private static String recursiveString(String st)
    {
    if(st==null)
    {
    if(st.length()

    • @Niceguy54444
      @Niceguy54444 4 роки тому

      public static String reverseStringRecursion(String input) {
      if(input.isEmpty())
      return "";
      System.out.println(input.charAt(input.length()-1));
      return input.charAt(input.length()-1)+reverseStringRecursion(input.substring(0,input.length()-1));
      }

  • @JASSININETY
    @JASSININETY 4 роки тому

    Clean and clear

  • @ankitarawat8264
    @ankitarawat8264 5 років тому

    Great👍

  • @AnirudhGarg1123
    @AnirudhGarg1123 4 роки тому +1

    Will this program run successfully if I don't use if else statement?

    • @sinaazartash3566
      @sinaazartash3566 4 роки тому

      I do not see how you could have a base case without an an if else statement. What I mean by base case is the return s statement. If there is no base case, then recursion cannot happen.

  • @sagarr.gs.m.s42
    @sagarr.gs.m.s42 4 роки тому

    Thanks a lot

  • @514-n8v
    @514-n8v 5 років тому

    superb sir