Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Post Timeline

Rollback to Revision 4 - Edit approval overridden by post owner or moderator
Source Link
Sami Eltamawy
  • 10k
  • 9
  • 50
  • 67

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] out=in = input.toCharArray();
 int nbegin=0;
 = out int end=in.length;length-1;
 forchar temp;
 while(intend>begin){
 i temp = 0;in[begin];
 i < n; i++){ in[begin]=in[end];
 out[n-1-i]in[end] = input.charAt(i)temp;
 end--;
 begin++;
 }
 return new String(outin);
}

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] out= input.toCharArray();
 int n = out.length;
 for(int i = 0; i < n; i++){
 out[n-1-i] = input.charAt(i);
 }
 return new String(out);
}

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] in = input.toCharArray();
 int begin=0;
  int end=in.length-1;
 char temp;
 while(end>begin){
 temp = in[begin];
  in[begin]=in[end];
 in[end] = temp;
 end--;
 begin++;
 }
 return new String(in);
}

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] in =out= input.toCharArray();
 int begin=0;
  n int= end=inout.length-1;
 char temp;length;
 whilefor(end>begin){
 int tempi = in[begin];
  in[begin]=in[end];
 0; i in[end]< =n; temp;i++){
 endout[n-1-;
 i] = begin++;input.charAt(i);
 }
 return new String(inout);
}

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] in = input.toCharArray();
 int begin=0;
  int end=in.length-1;
 char temp;
 while(end>begin){
  temp = in[begin];
  in[begin]=in[end];
  in[end] = temp;
 end--;
  begin++;
 }
 return new String(in);
}

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] out= input.toCharArray();
 int n = out.length;
 for(int i = 0; i < n; i++){
 out[n-1-i] = input.charAt(i);
 }
 return new String(out);
}
typo
Source Link
sfjac
  • 7.3k
  • 5
  • 49
  • 71

For Online Judges problems that does not allow StringBuidlderStringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] in = input.toCharArray();
 int begin=0;
 int end=in.length-1;
 char temp;
 while(end>begin){
 temp = in[begin];
 in[begin]=in[end];
 in[end] = temp;
 end--;
 begin++;
 }
 return new String(in);
}

For Online Judges problems that does not allow StringBuidlder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] in = input.toCharArray();
 int begin=0;
 int end=in.length-1;
 char temp;
 while(end>begin){
 temp = in[begin];
 in[begin]=in[end];
 in[end] = temp;
 end--;
 begin++;
 }
 return new String(in);
}

For Online Judges problems that does not allow StringBuilder or StringBuffer, you can do it in place using char[] as following:

public static String reverse(String input){
 char[] in = input.toCharArray();
 int begin=0;
 int end=in.length-1;
 char temp;
 while(end>begin){
 temp = in[begin];
 in[begin]=in[end];
 in[end] = temp;
 end--;
 begin++;
 }
 return new String(in);
}
added 8 characters in body
Source Link
Sami Eltamawy
  • 10k
  • 9
  • 50
  • 67
Loading
IndexOutOfBoundry bug fix
Source Link
Sami Eltamawy
  • 10k
  • 9
  • 50
  • 67
Loading
Source Link
Sami Eltamawy
  • 10k
  • 9
  • 50
  • 67
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /