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

22nd Mar 2018, 3:28 PM
Arjay
Arjay - avatar
6 Antworten
+ 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
22nd Mar 2018, 3:54 PM
Fata1 Err0r
Fata1 Err0r - avatar
22nd Mar 2018, 4:33 PM
Baraa AB
Baraa AB - avatar
+ 2
@Arjay you check my code which i made it to you..
23rd Mar 2018, 6:32 AM
Baraa AB
Baraa AB - avatar
+ 1
take a look at the StringBuilder class, it has a reverse method, otherwise use a for loop and do it step by step
22nd Mar 2018, 3:35 PM
Jeremy
Jeremy - avatar
0
hi sir jakob can you explain more how did that output runs
23rd Mar 2018, 5:30 AM
Arjay
Arjay - avatar
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
23rd Mar 2018, 8:18 AM
Arjay
Arjay - avatar