{"id":1066,"date":"2025-12-05T16:43:43","date_gmt":"2025-12-05T16:43:43","guid":{"rendered":"https:\/\/javigomez.org\/?p=1066"},"modified":"2025-12-05T16:52:18","modified_gmt":"2025-12-05T16:52:18","slug":"funciones-de-validacion-horas-y-minutos","status":"publish","type":"post","link":"https:\/\/javigomez.org\/index.php\/2025\/12\/05\/funciones-de-validacion-horas-y-minutos\/","title":{"rendered":"Funciones de validaci\u00f3n (horas y minutos)"},"content":{"rendered":"\n<p>Crear una funci\u00f3n llamada introHora que solicite un n\u00famero entero por pantalla entre 0 y 23 y lo devuelva. Crear una funci\u00f3n llamada introMinuto que solicite un n\u00famero entero por pantalla entre 0 y 59 y lo devuelva. Crear un programa que pida una hora y un minuto y lo muestre por pantalla.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import java.util.Scanner;<br><br>public class Tr04 {<br>    public static void main(String[] args) {<br>\/*<br>Crear una funci\u00f3n llamada introHora que solicite un<br>n\u00famero entero por pantalla entre 0 y 23 y lo devuelva.<br>Crear una funci\u00f3n llamada introMinuto que solicite un<br>n\u00famero entero por pantalla entre 0 y 59 y lo devuelva.<br>Crear un programa que pida una hora y un minuto y lo<br>muestre por pantalla.<br><br> *\/<br>        Scanner sc=new Scanner(System.<em>in<\/em>);<br>        int hh=<em>introHora<\/em>(sc);<br>        int mm=<em>introMinuto<\/em>(sc);<br>        System.<em>out<\/em>.println(hh + \":\"+mm);<br><br>    }<br><br>    private static int introHora(Scanner sc) {<br><br>        int hh=0;<br>        do {<br>            System.<em>out<\/em>.print(\"Intro Hora: \");<br>            hh=sc.nextInt();<br>            if (hh&lt;0||hh&gt;23)<br>                System.<em>out<\/em>.println(\"Hora incorrecta\");<br>        }while(hh&lt;0||hh&gt;23);<br>        return hh;<br>    }<br><br>    private static int introMinuto(Scanner sc) {<br><br>        int mm=0;<br>        do {<br>            System.<em>out<\/em>.print(\"Intro Minuto: \");<br>            mm=sc.nextInt();<br>            if (mm&lt;0||mm&gt;59)<br>                System.<em>out<\/em>.println(\"Minuto incorrect\");<br>        }while(mm&lt;0||mm&gt;59);<br>        return mm;<br>    }<br>}<\/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=\"Funciones de validaci\u00f3n (horas y minutos)\" width=\"1200\" height=\"900\" src=\"https:\/\/www.youtube.com\/embed\/MJj8rtGBt58?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>Crear una funci\u00f3n llamada introHora que solicite un n\u00famero entero por pantalla entre 0 y 23 y lo devuelva. Crear una funci\u00f3n llamada introMinuto que &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[203],"class_list":["post-1066","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"_links":{"self":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/1066","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=1066"}],"version-history":[{"count":1,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/1066\/revisions"}],"predecessor-version":[{"id":1067,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/posts\/1066\/revisions\/1067"}],"wp:attachment":[{"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/media?parent=1066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/categories?post=1066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/javigomez.org\/index.php\/wp-json\/wp\/v2\/tags?post=1066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}