{"id":806,"date":"2024-10-28T17:35:27","date_gmt":"2024-10-28T17:35:27","guid":{"rendered":"https:\/\/javigomez.org\/?p=806"},"modified":"2025-09-29T20:32:51","modified_gmt":"2025-09-29T20:32:51","slug":"e305-calculadora-en-java","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2024\/10\/28\/e305-calculadora-en-java\/","title":{"rendered":"E305. Calculadora en Java"},"content":{"rendered":"\n<p><strong>E305<\/strong><strong>.<\/strong>&nbsp;&nbsp;(<a href=\"https:\/\/youtu.be\/EGh-_RK5atY\">https:\/\/youtu.be\/EGh-_RK5atY<\/a>) Crea una aplicaci\u00f3n llamada Calculadora, nos pedir\u00e1 2 operandos (int) y un signo aritm\u00e9tico (char), seg\u00fan este \u00faltimo se realizar\u00e1 la operaci\u00f3n correspondiente. Al final mostrara el resultado en un cuadro de dialogo.<\/p>\n\n\n\n<p>Los signos aritm\u00e9ticos disponibles son:<\/p>\n\n\n\n<p>\u00b7+: suma los dos operandos.<\/p>\n\n\n\n<p>\u00b7-: resta los operandos.<\/p>\n\n\n\n<p>\u00b7*: multiplica los operandos.<\/p>\n\n\n\n<p>\u00b7\/: divide los operandos, este debe dar un resultado con decimales (double)<\/p>\n\n\n\n<p>\u00b7^: &nbsp;1\u00ba operando como base y 2\u00ba como exponente.<\/p>\n\n\n\n<p>\u00b7%: &nbsp;m\u00f3dulo, resto de la divisi\u00f3n entre operando1 y operando2.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package U03;\n\/*\n * E305.\u00a0\u00a0Crea una aplicaci\u00f3n llamada Calculadora, \n * nos pedir\u00e1 2 operandos (int) y un signo aritm\u00e9tico (char), \n * seg\u00fan este \u00faltimo se realizar\u00e1 la operaci\u00f3n correspondiente. \n * Al final mostrara el resultado en un cuadro de dialogo.\n *\/\nimport java.util.Scanner;\n\npublic class E3_05 {\n\n\tpublic static void main(String&#91;] args) {\n\t\tScanner sc=new Scanner(System.in);\n\t\tSystem.out.println(\"Dato 1:\");\n\t\tint dato1=sc.nextInt();\n\t\t\n\t\tSystem.out.println(\"Dato 2:\");\n\t\tint dato2=sc.nextInt();\n\n\t\tSystem.out.println(\"Oper:\");\n\t\tchar oper=sc.next().charAt(0);\n\t\t\n\t\tint res=switch(oper) {\n\t\tcase '+' -> {yield dato1+dato2;}\n\t\tcase '-' -> {yield dato1-dato2;}\n\t\tcase '*' -> {yield dato1*dato2;}\n\t\tcase '\/' -> {yield dato1\/dato2;}\n\t\tdefault -> {yield -9999;}\n\t\t};\n\t\t\n\t\tSystem.out.println(\"Resultado: \"+ res);\n\n\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-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Java U03 05 calculadora\" width=\"1200\" height=\"900\" src=\"https:\/\/www.youtube.com\/embed\/EGh-_RK5atY?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>E305.&nbsp;&nbsp;(https:\/\/youtu.be\/EGh-_RK5atY) Crea una aplicaci\u00f3n llamada Calculadora, nos pedir\u00e1 2 operandos (int) y un signo aritm\u00e9tico (char), seg\u00fan este \u00faltimo se realizar\u00e1 la operaci\u00f3n correspondiente. Al &hellip; <\/p>\n","protected":false},"author":1,"featured_media":807,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[65,203],"class_list":["post-806","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-calculadora","tag-java"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/806","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=806"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/806\/revisions"}],"predecessor-version":[{"id":840,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/806\/revisions\/840"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/807"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}