0
Can you help me this exercise
Write a program that uses a string as input and outputs it backwards in the result. This code takes a string and translates it into a char array. Example of input data: hello there Example result: ereht olleh
5 odpowiedzi
+ 3
Please link your code attempt.
Hint: use a loop
+ 1
Ralf Schoenian why 2 loops?
Anyways, I think it would be more helpful if you explained how you approached the problem instead of just giving ready-made code
0
Just print in reverse order
0
Try this:
package playground;
public class ReverseString {
public static void main(String[] args) {
String myString = "Hello there";
char[] result = new char[myString.length()];
int counter = 0;
for (int i=myString.length()-1; i>=0; i--) {
result[counter] = myString.charAt(i);
counter++;
}
for (int i=0; i < result.length;i++) {
System.out.print(result[i]);
}
}
}
0
@Lisa, of course, you're right. One loop would be enough, but on the other hand "df dfhg" was asked to use an array.