Printing reverse of any String without using any predefined function?

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

    import java.util.*;
    public class Restring {
    
    public static void main(String[] args) {
      String input,output;
      Scanner kbd=new Scanner(System.in);
      System.out.println("Please Enter a String");
      input=kbd.nextLine();
      int n=input.length();
    
      char tmp[]=new char[n];
      char nxt[]=new char[n];
    
      tmp=input.toCharArray();
      int m=0;
      for(int i=n-1;i>=0;i--)
      {
          nxt[m]=tmp[i];
          m++;
      }
    
      System.out.print("Reversed String is   ");
      for(int i=0;i

提交回复
热议问题