+ 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
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
+ 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
+ 1
Thanks so much for the help and the explanation!!