Printing reverse of any String without using any predefined function?

后端 未结 30 1376
生来不讨喜
生来不讨喜 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:20

    public class ReverseString {
    
    public static void main(String [] args) {
    
        String s = "reverse string" ;
        String b = "";
    
                for (int i = 0; i < s.length(); i++ ){
                     b= b + s.substring(s.length()-1-i, s.length()-i);
    
                     }
    
                 System.out.println(b);
    }
    

提交回复
热议问题