TRUCOS JAVA

Page 476

Guía de sintaxis

467

[catch (tipoExcepcion2 identificadoz-2) boqueSen t en cia s2]

... [finally

boqueSen t enciashr]

o bien try bl oqueAin ten t a r finally boquesen tenciasN

ya que el bloque try no puede aparecer sólo.

import java.io.*; public class ReturnTryEj {

public s t a t i c i n t leer ( )

i InputStreamReader isr = new InputStreamReader(System.in); Buf feredReader br = new Buf feredReader (isr); String cadena = 'I";

try {

cadena = br . readLine ( ) ; return Integer .parseInt (cadena);

1 catch (Exception e) {

(e instanceof IOException) System.out .print111("Error de entrada/salida") ; else i f (e instanceof NumberFormatException) System.out .println ("No tecleó un número entero") ; if

1 / / Instrucción siguiente a catch System.out .print111("Se devuelve O") ; return O;

public s t a t i c void main (String args [ ] t

i n t n; do {

)


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.