{"id":683,"date":"2024-03-01T16:01:56","date_gmt":"2024-03-01T16:01:56","guid":{"rendered":"https:\/\/javigomez.org\/?p=683"},"modified":"2025-09-29T20:33:16","modified_gmt":"2025-09-29T20:33:16","slug":"u11-02-try-catch-introduccion-de-datos","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2024\/03\/01\/u11-02-try-catch-introduccion-de-datos\/","title":{"rendered":"U11-03-try catch Introducci\u00f3n de Datos"},"content":{"rendered":"\n<p>Utilizaci\u00f3n del try catch para validar la informaci\u00f3n que introduce un usuario. <\/p>\n\n\n\n<p>La funci\u00f3n est\u00e1 realiza con un bucle y otra manera de realizarlo es con recursividad.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package U11;\n\nimport java.util.Scanner;\n\npublic class A01003 {\n\n\tpublic static void main(String&#91;] args) {\n\n\t\tint r = introInt();\n\t\tSystem.out.println(r);\n\n\t}\n\tprivate static int introInt() {\n\t\tint r=0;\n\t\ttry {\n\t\t\tr = new Scanner(System.in).nextInt();\n\t\t} catch (Exception e) {\n\t\t\tSystem.out.println(\"Error\");\n\t\t\tr=introInt();\n\t\t}\n\t\treturn r;\n\t}\n\n\t\/*\n\tprivate static int introInt() {\n\t\tint r = 0;\n\t\tboolean salir = false;\n\t\tdo {\n\t\t\ttry {\n\t\t\t\tr = new Scanner(System.in).nextInt();\n\t\t\t\tsalir = true;\n\t\t\t} catch (Exception e) {\n\t\t\t\tSystem.out.println(\"Error\");\n\t\t\t}\n\t\t} while (!salir);\n\n\t\treturn r;\n\t}\n\t*\/\n\n}\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Java U11 03 try catch IntroducionDatos\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/YjPFoLm-ssw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Utilizaci\u00f3n del try catch para validar la informaci\u00f3n que introduce un usuario. La funci\u00f3n est\u00e1 realiza con un bucle y otra manera de realizarlo es &hellip; <\/p>\n","protected":false},"author":1,"featured_media":684,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[132,139,203,334],"class_list":["post-683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-entrada-de-datos","tag-exception","tag-java","tag-try-catch"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/683","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/comments?post=683"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/683\/revisions"}],"predecessor-version":[{"id":876,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/683\/revisions\/876"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/684"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}