Printing reverse of any String without using any predefined function?

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

    String a="Siva";
    
    for(int i=0;i<=a.length()-1;i++){
        System.out.print(a.charAt(i));
    }
    
    for(int i = a.length() - 1; i >= 0; --i){
        System.out.println(a.charAt(i)); 
    }
    

提交回复
热议问题