0
To reverse the String by implementing the replace() method in java
I'm try to do it but yet not be able to figure it out any solution for it. Here is my attempt !!! https://code.sololearn.com/cJv45cV3gsPj/?ref=app
13 Respostas
+ 1
public class Program
{
public static void main(String[] args) {
String x = "Trial Letter";
char[] y = x.toCharArray();
int size = y.length;
char[] a = new char[size];
int i = 0;
while(i != size){
a[i] = y[size - 1 - i];
++i;
}
String reverse = x.replace(x,String.valueOf(a));
System.out.println(x);
System.out.println(a);
System.out.println(reverse);
}
}
+ 4
Check this. Done by Me. We can do in two way.
https://code.sololearn.com/cuwF40LI0114/?ref=app
+ 2
Agron Check your while loop. It will be like this
while(i != size) {
a[i] = y[size - 1 - i];
i++;
}
+ 1
you're using different kind of space. i clean up the code a bit, but its same as yours
https://code.sololearn.com/cOG64U9R9Os7/?ref=app
+ 1
you're on the track with your code with those commented lines.
+ 1
if each character are unique, you can use my first answer. but it isnt, the only way i can think of by using your method which you almost got it.
copy the string, reverse it.
use replace with it.
0
replace char at 0 with chat at n
then char at 1 with char at n-1
etc.
depend on the string this may not work
0
i check your code. you're using nbsp instead of normal space.
its funny that non breaking space is actually breaking the program
0
So far i have tried to, make changes with different solutions.
But still not be able to got the expected output.
It's weird that on the mobile version, it gives me compilation error. But on web version its runs nicely.
0
Thank you guys !!!
Those approaches are nice & clean.
just to shair that,
For there my main purpose is to incorporate replace() method in it, so to perform the string reverse in it
0
to be honest, i would like to know how we can achieve it by replacement method on it.
Sorry for being for nastier here guys đ
0
It's true
but I'm not be able to got the way, to make it.
Still trying to make some changes, if it's not gone work.
Then i will try to do it later.
But i will make it.
Because i wanted to know how to make it possible by this.
0
I have obtain the correct solution for it.
Thank you so much guys for all of your help here.