Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ejercicio4 {
- @SuppressWarnings("null")
- public void nulo(){
- Object a = null;
- try{
- a.toString();
- } catch(NullPointerException n){
- System.out.println("El objeto no tiene un valor valido");
- }
- }
- public void arrayBounds(){
- int[] array = {2,6,7};
- try{
- for (int i = 0; i > 100; i++){
- System.out.println(array[i]);
- }
- } catch (ArrayIndexOutOfBoundsException a){
- System.out.println("La posicion del array no existe");
- }
- }
- public void stringANumerico(){
- String s = "5";
- try{
- int x = Integer.parseInt(s);
- System.out.println(x);
- } catch (NumberFormatException f){
- System.out.println("El string no se pudo convertir a formato numerico");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement