{"id":545,"date":"2023-11-27T17:46:05","date_gmt":"2023-11-27T17:46:05","guid":{"rendered":"https:\/\/javigomez.org\/?p=545"},"modified":"2025-09-29T20:33:44","modified_gmt":"2025-09-29T20:33:44","slug":"u05-03-funciones-valor-de-salida","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2023\/11\/27\/u05-03-funciones-valor-de-salida\/","title":{"rendered":"U05-03-Funciones: valor de salida"},"content":{"rendered":"\n<p>Igual que a una funci\u00f3n se le puede pasar varios par\u00e1metros de entrada, una funci\u00f3n solo tendr\u00e1 un valor de salida, aunque este, puede ser todo lo complejo que se quiera (un valor, un array, un array de objetos&#8230;.). El tipo de dato de la funci\u00f3n depender\u00e1 del tipo de dato del valor devuelto.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class A000 {\n\t\n\tpublic static void main(String&#91;] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tSystem.out.println(\"Dato 1:\");\n\t\tint dato1 = sc.nextInt();\n\t\t\t\t\n\n\t\tSystem.out.println(\"Dato 2:\");\n\t\tint dato2 = sc.nextInt();\n\t\t\n\t\tint total = suma(dato1, dato2);\n\t\t\n\t\tSystem.out.println(\"El total es: \" + total);\n\t\t\n\t}\n\t\n\tstatic int suma(int d1, int d2) {\n\t\tint t=d1+d2;\n\t\t\n\t\treturn(t);\n\t}\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class A000 {\n\t\n\tpublic static void main(String&#91;] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tSystem.out.println(\"Dato 1:\");\n\t\tint dato1 = sc.nextInt();\n\n\t\tSystem.out.println(\"Dato 2:\");\n\t\tint dato2 = sc.nextInt();\n\t\t\n\t\tint maximo = max(dato1, dato2);\n\t\t\n\t\tSystem.out.println(\"El maximo: \" + maximo);\n\t\t\n\t}\n\t\n\tstatic int max(int d1, int d2) {\n\t\tint maximo=0;\n\t\t\n\t\tif (d1>d2)\n\t\t\tmaximo = d1;\n\t\telse\n\t\t\tmaximo = d2;\n\t\treturn(maximo);\n\t}\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Scanner;\n\npublic class A000 {\n\t\n\tpublic static void main(String&#91;] args) {\n\t\t\n\t\tScanner sc = new Scanner(System.in);\n\t\t\n\t\tSystem.out.println(\"Dato 1:\");\n\t\tint dato1 = sc.nextInt();\n\t\t\n\t\tSystem.out.println((esPrimo(dato1)));\n\t}\n\t\n\tstatic boolean esPrimo(int d1) {\n\t\tboolean primo = true;\n\t\tint i=2;\n\t\tfor (int j=2;j&lt;d1;j++) {\n\t\t\tif (d1%j==0){\n\t\t\t\tprimo=false;\n\t\t\t}\n\t\t}\n\t\treturn primo;\n\t}\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 U05 02 funciones valor salida\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/NuhtFrq--Oc?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>Igual que a una funci\u00f3n se le puede pasar varios par\u00e1metros de entrada, una funci\u00f3n solo tendr\u00e1 un valor de salida, aunque este, puede ser &hellip; <\/p>\n","protected":false},"author":1,"featured_media":548,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[167,203,291,339],"class_list":["post-545","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-funciones","tag-java","tag-return","tag-valores-de-salida"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/545","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=545"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":912,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/545\/revisions\/912"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media\/548"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}