Advertisement
fmbalvarez

Guía 2 - Ejercicio 4

Mar 24th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1.  
  2. public class ejercicio4 {
  3.    
  4.     @SuppressWarnings("null")
  5.     public void nulo(){
  6.        
  7.         Object a = null;
  8.        
  9.         try{
  10.             a.toString();
  11.         } catch(NullPointerException n){
  12.             System.out.println("El objeto no tiene un valor valido");
  13.         }
  14.     }
  15.    
  16.     public void arrayBounds(){
  17.        
  18.         int[] array = {2,6,7};
  19.        
  20.         try{
  21.             for (int i = 0; i > 100; i++){
  22.                 System.out.println(array[i]);
  23.             }
  24.         } catch (ArrayIndexOutOfBoundsException a){
  25.             System.out.println("La posicion del array no existe");
  26.         }
  27.     }
  28.    
  29.     public void stringANumerico(){
  30.        
  31.         String s = "5";
  32.        
  33.         try{
  34.             int x = Integer.parseInt(s);
  35.             System.out.println(x);
  36.         } catch (NumberFormatException f){
  37.             System.out.println("El string no se pudo convertir a formato numerico");
  38.         }
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement