Please implement an algorithm, without the use of additional storage space and data structures, flipping a given string (using a single process variable).

import java.util.Scanner;
/ **

  • Please @description TODO implement an algorithm, without the use of additional storage space and data structures, flipping a given string (using a single process variable).
  • @date 2019/2/25 PM 5:28 Taken
    ** /
    public class the Test {
    public static void main (String [] args) {
    of System.out.print ( "Please enter the string: \ n-");
    Scanner new new SR1 = Scanner (System.in);
    string I1 = sr1.nextLine (); // keyboard receive the string
    System.out.println ( "string you entered is: \ the n-" + I1);
    int the n-i1.length = ( );
    char [] = CH i1.toCharArray ();
    for (int I = 0; I <n-/ 2; I ++)
    {the swap (CH, I,. 1-n--I);}
    String str1 = new new String (CH );
    System.out.println ( "reversed string: \ n-" + str1);
    }
    public static void the swap (char [] X, a int, int B) {
    char X T = [a];
    X [ A] = X [B];
    X [B] = T;
    }
    // public static void main (string [] args) {
    // of System.out.print ( "Please enter the string: \ n");
    Scanner Scanner new new SR1 = // (System.in);
    // String str1 = sr1.nextLine (); // keyboard receives a string
    // System.out.println ( "string you entered is: \ n" + str1);
    // int = n-str1.length ();
    // IF (n-<= str1 == null ||. 1)
    // System.out.println ( "string reversed: \ n" + str1) ;
    // the else {
    // the StringBuffer the StringBuffer new new SB = ();
    // for (int. 1-n-= I; I> = 0; i--)
    // sb.append (str1.charAt (I));
    / / System.out.println ( "reversed string: \ n-" + sb.toString ());}
    //}
    }

Guess you like

Origin www.cnblogs.com/zhangke306shdx/p/11074891.html