+ 1

Can somebody help me with this exercise? 3rd Module on Java

Hi guys, im just trying to make the output as a reversed input. For example, user input´s: Hello. Then the output should be: olleH I let you there my attempt. Thanks https://code.sololearn.com/ca16A2a9a10a

15th Feb 2021, 8:11 PM
Ulises
Ulises - avatar
3 Respuestas
+ 1
just do something like this do { novo[q-1] = arr[a]; q--; a++; } while (q>0); System.out.println(novo); ofcourse theres easier ways to reverse a string in java
15th Feb 2021, 8:55 PM
Anastacia Ru
Anastacia Ru - avatar
+ 1
in your code you can just do: char[] arr = scanner.nextLine().toCharArray(); the problem in your code is that you are going out of bounds if u have the string "Hello" the length is 5 but its position in the array is 4, because we start from zero, so you can't do novo[5] in your code you should do novo[q-1] = arr[a]; and theres reallly no need for that if(a==z) you can just print it outside the do-while and your condition for the do while can be while q>0
15th Feb 2021, 8:53 PM
Anastacia Ru
Anastacia Ru - avatar
+ 1
Thanks so much for the help and the explanation!!
15th Feb 2021, 9:24 PM
Ulises
Ulises - avatar