import java.io.*; class Transponer { public static String invertir(String str ) { int i = 0 , j = str.length() - 1; char aux[] = str.toCharArray(); /* retorna el string como un arreglo de caracteres */ char tmp; while(i < j) { tmp = aux[i]; aux[i] = aux[j]; aux[j] = tmp; i++; j--; } return new String(aux); } public static void main(String arg[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String frase, resultado = ""; int i, pi, pf; /* posicion inicial y final del substring */ System.out.print("Ingrese frase : "); frase = in.readLine(); pi = 0; for(i = 0; i < frase.length(); i++) { if( frase.charAt(i) == ' ') { resultado += invertir( frase.substring(pi,i) ) + " "; pi = i; } } if (pi < frase.length()) { System.out.println("ultimo sub : " + frase.substring(pi,frase.length())); resultado += invertir(frase.substring(pi,frase.length())); } System.out.println(resultado); } }