Printing reverse of any String without using any predefined function?

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

    public class ReverseString {
    
    public static void main(String[] args) {
    
        reverseString("HELLO");
    }
    
    public static String reverseString(String s){
        char []arr=s.toCharArray();
        for(int i= (arr.length)-1;i>=0;i--){
            System.out.print(arr[i]);
        }
        String str=String.copyValueOf(arr);
        return str;
    }
    

提交回复
热议问题