Printing reverse of any String without using any predefined function?

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

    public class StringReverse {
    
        public static void main(String[] args) {
            String s= (args[0]);
            for (int i =s.length()-1; i >= 0; i--) {            
                   System.out.print(s.charAt(i));    
            }
        } 
    }
    

    Prints the reversed string of the input.

提交回复
热议问题