Printing reverse of any String without using any predefined function?

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

     public class ReverseWithoutStringAPI {
    
    public static void main(String[] args) {
    
          String st="hello";
    
            StringBuffer b=new StringBuffer();
    
            for(int i=st.length()-1;i>=0;i--){
    
                b.append(st.charAt(i)); }
    
            System.out.println("reverse:::"+b);
    }
    }
    

提交回复
热议问题