How can i solve the third proyect of Java? (Reverse String)
This is my actual code: It's modified to work with a specific string, "How are you", the program should reverse the string, but doesn't work. If i erase the caracter "?" the program works correctly, what's the problem? :( //import java.util.Scanner; public class program{ public static void main(String[] args){ //Scanner scanner = new Scanner(System.in); System.out.println("Inserta un texto a invertir"); String text = "How are you?";//scanner.nextLine(); char[] arr = text.toCharArray(); for(int i= 0; i< arr.length -1; i++){ if(i == arr.length-(i+1)){ break; } char cambio1 = arr[arr.length-(i+1)]; char cambio2 = arr[i]; arr[arr.length-(i+1)] = cambio2; arr[i] = cambio1; } for(int i= 0; i<= arr.length -1; i++){ System.out.println(arr[i]); } } }