Qsqsq

Páginas: 8 (1900 palabras) Publicado: 13 de noviembre de 2012
(MHUFLFLRVH[FHSFLRQHVHMHUFLFLR ,
EXCEPCIONES

• (QXQFLDGR
• (QGHWHUPLQDGRVIUDJPHQWRVGHOVLJXLHQWHFyGLJRVHSXHGHJHQHUDU
ODVVLJXLHQWHVH[FHSFLRQHVRuntimeException-DYD
• NullPointerException
• IndexOutOfBoundsException

• 7DPELpQDSDUHFHODJHVWLyQGHODH[FHSFLyQIOExceptionQRKHUHGHUD
GHRuntimeException
•$xDGDDOFyGLJRORTXHFRQVLGHUHRSRUWXQRSDUDTXHQLQJXQDGHODV
H[FHSFLRQHVRuntimeExceptionPHQFLRQDGDV´OOHJXHDODPiTXLQDYLUWXDO
GH-DYDµ

3URJUDPDFLyQ2ULHQWDGDD2EMHWRV



(MHUFLFLRVH[FHSFLRQHVHMHUFLFLR ,,
EXCEPCIONES

• )LFKHUR(M*VWQ([FSFQVMDYD
import java.io.*;
public class EjGstnExcpcns2 {
public static String [] datos = new String [2];
public static void mostrar(int num_datos){
for (int i=0; i < num_datos; i++) {System.out.println("EL DATO EN LA POSICION "+i+" ES :"+datos[i]);}}
public static void mostrarLongitudes(int num_datos) {
for (int i=0; i < num_datos; i++) {
System.out.println("EL DATO EN LA POSICION "+i+" ES :"+datos[i]);
System.out.println("Y SU LONGITUD "+datos[i].length()); }}
public static void asignarDatoAPosicion(String dato, int pos) {
datos[pos]=dato;}3URJUDPDFLyQ2ULHQWDGDD2EMHWRV



(MHUFLFLRVH[FHSFLRQHVHMHUFLFLR ,,,
EXCEPCIONES

• )LFKHUR(M*VWQ([FSFQVMDYD
public static int obtenerOpcion(BufferedReader br)
{
String str_opcion=null;
int opcion;
System.out.println("\tSELECCIONE LA ACCION QUE QUIERE REALIZAR");
System.out.println("\t\t\t1:\tMOSTRAR DATOS");
System.out.println("\t\t\t2:\tANADIR DATO");
System.out.println("\t\t\t3:\tMOSTRARLA LONGITUD DE DATOS");
System.out.println("\t\t\t4:\tSALIR");
try {str_opcion= br.readLine();}catch (IOException e){}
return opcion=Integer.decode(str_opcion).intValue();
}

3URJUDPDFLyQ2ULHQWDGDD2EMHWRV



(MHUFLFLRVH[FHSFLRQHVHMHUFLFLR ,9
EXCEPCIONES

• )LFKHUR(M*VWQ([FSFQVMDYD
public static void anadirDato(BufferedReader br)
{
String dato= null;
Stringstr_posicion = null;
int posicion;
System.out.println("ESCRIBA EL DATO QUE QUIERE ANADIR");
try {dato= br.readLine();}catch (IOException e){}
System.out.println("ESCRIBA LA POSICION EN LA QUIERE ANADIRLO");
try {str_posicion= br.readLine();}catch (IOException e){}
posicion=Integer.decode(str_posicion).intValue();
asignarDatoAPosicion( dato, posicion );
}

3URJUDPDFLyQ2ULHQWDGDD2EMHWRV

 (MHUFLFLRVH[FHSFLRQHVHMHUFLFLR 9
EXCEPCIONES

• )LFKHUR(M*VWQ([FSFQVMDYD
public static void mostrarDatos(BufferedReader br){
String str_num_datos = null;
int num_datos;
System.out.println("ESCRIBA EL NUMEROS DE DATOS QUE QUIERE MOSTRAR");
try {str_num_datos= br.readLine();}catch (IOException e){}
num_datos=Integer.decode(str_num_datos).intValue();
mostrar(num_datos);
}public static void mostrarLongitudDatos(BufferedReader br){
String str_num_datos = null;
int num_datos;
System.out.println("ESCRIBA EL NUMEROS DE DATOS CUYA LONGITUD QUIERE MOSTRAR");
try {str_num_datos= br.readLine();}catch (IOException e){}
num_datos=Integer.decode(str_num_datos).intValue();
mostrarLongitudes(num_datos);
}

3URJUDPDFLyQ2ULHQWDGDD2EMHWRV

 (MHUFLFLRVH[FHSFLRQHVHMHUFLFLR 9,
EXCEPCIONES

• )LFKHUR(M*VWQ([FSFQVMDYD
public static void main (String [] args){
int opcion=0;
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
while (opcion != 4)
{
opcion = obtenerOpcion(br);
switch(opcion)
{
case 1:{ mostrarDatos(br); break;}
case 2:{ anadirDato(br); break; }
case 3:{ mostrarLongitudDatos(br); break; }
case 4:{System.exit(0); break; }
default:{ }
}
}
}
}

3URJUDPDFLyQ2ULHQWDGDD2EMHWRV



(MHUFLFLRVH[FHSFLRQHVHMHUFLFLR 9,,
EXCEPCIONES

• 6ROXFLyQ3ULPHUR¢GyQGHVHSXHGHJHQHUDUODVH[FHSFLRQHV"
import java.io.*;
public class EjGstnExcpcns2 {
public static String [] datos = new String [2];
public static void mostrar(int num_datos){
for (int i=0; i < num_datos; i++) {...
Leer documento completo

Regístrate para leer el documento completo.

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS