• Lenguaje

    JSP

  • Descripción

    Simula el funcionamiento de una calculadora que realiza las operaciones básicas de SUMA, RESTA, MULTIPLICACIÓN y DIVISIÓN. El algoritmo debe mostrar un mensaje de ¿DESEA CONTINUAR[S/N]? El algoritmo se detiene si se presiona la letra [N].

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!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>Suma, resta, multiplicación y división</title>
    </head>
    <body>
<%
    if (request.getMethod().equals("POST")) {
        double a, b, division, multiplicacion, resta;
        double suma;
        a = Double.parseDouble(request.getParameter("a"));
        b = Double.parseDouble(request.getParameter("b"));
        suma=a+b;
        resta=a-b;
        multiplicacion=a*b;
        if(b==0)
            division=0;
        else
            division=a/b;
        out.println("Valor de division: " + division + "<br/>");
        out.println("Valor de multiplicacion: " + multiplicacion + "<br/>");
        out.println("Valor de resta: " + resta + "<br/>");
        out.println("Valor de suma: " + suma + "<br/>");
    }
%>
        <form method="post">
            <table style="text-align: left; margin-left: auto; margin-right: auto;" border="1" cellpadding="1" cellspacing="1">
                <tbody>
                    <tr>
                        <td>
                            <label for="a">Ingresa el valor de a:</label>
                        </td>
                        <td>
                            <input name="a" required="required" step="0.000001" type="number" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="b">Ingresa el valor de b:</label>
                        </td>
                        <td>
                            <input name="b" required="required" step="0.000001" type="number" />
                        </td>
                    </tr>
                    <tr align="center">
                        <td colspan="2" rowspan="1">
                            <input value="Procesar" type="submit" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </body>
</html>