+ 1
Reversing a string
Need assistance with the code for reversing a string. I need to write a program to take a string as input and output its reverse. The given code takes a string as input and converts it into a char array, which contains letters of the string as its elements. Please Help!
8 odpowiedzi
+ 6
Onica Victory ,
i can not find any hint what programming language you are going to use.
can you please update your post with this information? please use the tags to do so.
+ 6
Mohammad Hakim Monib ,
please do not give ready made codes, since the asker has not shown any attempt that he has done by himself.
it does not really help the asker to develop his coding skills and building up the required experience.
it is better to give hints and tips, so that the asker has the opportunity to solve the task.
+ 5
gonel Could you please refrain from spoonfeeding people solutions?
Sure you meant to help but that's not how people learn. Plus no one should ask others to invest time for things that they choose not to, themselves. (The OP has shown no attempt)
+ 2
string = input()
a=[]
r_string = string[::-1]
for i in r_string:
a.append(i)
#first we are taking input, then we are using for loop to append letters to char array as I wrote above.
+ 2
gonel Thank you, have a good one! ☺️
+ 1
Korkunç el Gato ok next time I won't do it like that. Thank you for advice.
0
Ok good idea;
But sometime code sharing is good.
- 3
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in); String n = "45799";
String rev = "";
for(int i = n.length()-1; i>=0;i--){
rev = rev + n.charAt(i);
}
System.out.println(rev);
}
}