----------------------------------------------------------------------------------------------------------
public class Stringlegh {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {//Leght, getChars, CharaRT
String s1 = "hola a todos";
char arregloChar[]= new char [5];
System.out.printf( "s1; %s ", s1);
//Prueba metodo Leght
System.out.printf( "\nLongitud de s1: %d ",s1.length() );
//Esta linea se mostrara invertida
System.out.printf ( "\nLa Cadena invertida es: " );
for (int cuenta = s1.length() -1; cuenta >=0; cuenta--)
System.out.printf ( "%s", s1.charAt(cuenta) );
//Copía los caracteres de la cadena Arreglo char
s1.getChars(0,4, arregloChar, 0);
System.out.print ("\nEl arreglo de caracteres es:");
for (char caracter : arregloChar)
System.out.print(caracter);
System.out.println("");
}//fin de main
}//fin de la clase
-----------------------------------------------------------------------------------------------
Otro ejemplo pero solo con getChars
public class StringEP {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String A = "Ernesto el mariachi";
char arregloChar[] = new char[ 19 ];
A.getChars(11,19, arregloChar, 0);
System.out.println("\nLa parte selecciona es:" );
for ( char caracter : arregloChar )
System.out.print( caracter );
}
}
No hay comentarios.:
Publicar un comentario