Printing reverse of any String without using any predefined function?

后端 未结 30 1394
生来不讨喜
生来不讨喜 2020-11-30 03:08

How to print the reverse of the String java is object orientated language without using any predefined function like reverse()?

30条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 03:22

    this is the best solution for this

    public class String_rev {
    public static void main(String[] args) {
        String str="Karan Rajput";
        int ln=str.length();
        for (int i = ln; i > 0; i--) {
            System.out.print(str.charAt(i-1));
        }
    }
    

    }

提交回复
热议问题