• Lenguaje

    JSP

  • Descripción

    Generar números aleatorios entre 1 y 10.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.Random" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Aleatorios entre 1 y 10</title>
    </head>
    <body>
<%
    if (request.getMethod().equals("POST")) {
        int numero_aleatorio;
        Random rand = new Random();
        numero_aleatorio=1+rand.nextInt(10);
        out.println("Valor de numero aleatorio: " + numero_aleatorio + "<br/>");
    }
%>
        <form method="post">
            <table style="text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="1" cellspacing="1">
                <tbody>
                    <tr align="center">
                        <td colspan="2" rowspan="1">
                            <input value="Procesar" type="submit" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>