0
How can you reverse a word in java? Like this input:hello world output: dlrow olleh. Please explain thanks in advance
java reverse word
6 Réponses
+ 2
As Jeremy said, use the built-in methods to do this easily or use a loop for it. Since I already answered this for someone else earlier (about how to do it without using reverse() ), here is what I posted for them.
Hope it helps.
JAVA:
https://code.sololearn.com/cVD4wXKq3g2y/#java
public class Program
{
public static void main(String[] args) {
String forward = "This is my string!";
String backward = "";
for(int i = forward.length()-1; i >= 0; --i){
backward += forward.charAt(i);
}
System.out.println(backward);
}
}
:::::: OUTPUT ::::::
!gnirts ym si sihT
+ 6
Check my code:
https://code.sololearn.com/cE4qZAIUBA5G/#java
+ 2
@Arjay you check my code which i made it to you..
+ 1
take a look at the StringBuilder class, it has a reverse method, otherwise use a for loop and do it step by step
0
hi sir jakob can you explain more how did that output runs
0
@Baara sir can you explain more how did it reverse the string? im sorry sir im just a beginner i want to learn more in java thanks in advance sir