Bueno chicos vengo a compartir esto por si alguno lo necesita para alguna prueba o tarea.
Es una calculadora super basica pero quien sabe puede salvar una tarea pajera jaja.
Ver el archivos adjunto 1.jpg
Este es el codigo de la calculadora:
</head>
<body>
<%String unox = request.getParameter("uno");
String dosy = request.getParameter("dos");
String op =request.getParameter("operat");%>
<div id="cuerpo">
<form action="" mehotd="GET">
<div id="tuno">
<table align="center">
<tr>
<td>
<label>X</label>
</td>
<td>
<input type="text" value="<%=(unox!=null)?unox:0 %>" name="uno">
</td>
</tr>
<tr>
<td>
<label>Y</label>
</td>
<td>
<input type="text" value="<%=(dosy!=null)?dosy:0 %>" name="dos">
</td>
</tr>
<table align="center">
<tr>
<td>
<input type="submit" value="+" name="operat" />
<input type="submit" value="-" name="operat" />
<input type="submit" value="*" name="operat" />
<input type="submit" value="/" name="operat" />
</td>
</tr>
</table>
</form>
</div>
</table>
<%
try
{
if(unox!=null || dosy!=null)
{
double n1=Double.parseDouble(unox);
double n2=Double.parseDouble(dosy);
if(op.equals("+"))
{
double res=n1+n2;
out.print("<h1>"+n1+"+"+n2+"="+ res + "</h1>");
}
if(op.equals("-"))
{
double res=n1-n2;
out.print("<h1>"+n1+"-"+n2+"="+ res + "</h1>");
}
if(op.equals("/"))
{
if(n2!=0)
{
double res1=n1/n2;
out.print("<h1>"+n1+"/"+n2+"="+ res1 + "</h1" );
}
else
{
out.print("<p><div id=\"error\"><h1>no se puede dividir por cero!</h1></div></p>");
}
}
if(op.equals("*"))
{
double res=n1*n2;
out.print("<h1>"+n1+"*"+n2+"="+ res + "</h1>");
}
}
}
catch(java.lang.NumberFormatException error)
{
out.print("<p><div id=\"error\"><h1>Solo ingresar numeros</h1></div></p>");
}
%>
</body>
</html>
---------------------------------------------------------------------
Este seria el codigo css(muy basico)
table
{
background-color:#FFFF22;
align="center"
margin: 0 auto;
}
#error
{
color:red;
margin: 0 auto;
}
Es una calculadora super basica pero quien sabe puede salvar una tarea pajera jaja.
Ver el archivos adjunto 1.jpg
Este es el codigo de la calculadora:
</head>
<body>
<%String unox = request.getParameter("uno");
String dosy = request.getParameter("dos");
String op =request.getParameter("operat");%>
<div id="cuerpo">
<form action="" mehotd="GET">
<div id="tuno">
<table align="center">
<tr>
<td>
<label>X</label>
</td>
<td>
<input type="text" value="<%=(unox!=null)?unox:0 %>" name="uno">
</td>
</tr>
<tr>
<td>
<label>Y</label>
</td>
<td>
<input type="text" value="<%=(dosy!=null)?dosy:0 %>" name="dos">
</td>
</tr>
<table align="center">
<tr>
<td>
<input type="submit" value="+" name="operat" />
<input type="submit" value="-" name="operat" />
<input type="submit" value="*" name="operat" />
<input type="submit" value="/" name="operat" />
</td>
</tr>
</table>
</form>
</div>
</table>
<%
try
{
if(unox!=null || dosy!=null)
{
double n1=Double.parseDouble(unox);
double n2=Double.parseDouble(dosy);
if(op.equals("+"))
{
double res=n1+n2;
out.print("<h1>"+n1+"+"+n2+"="+ res + "</h1>");
}
if(op.equals("-"))
{
double res=n1-n2;
out.print("<h1>"+n1+"-"+n2+"="+ res + "</h1>");
}
if(op.equals("/"))
{
if(n2!=0)
{
double res1=n1/n2;
out.print("<h1>"+n1+"/"+n2+"="+ res1 + "</h1" );
}
else
{
out.print("<p><div id=\"error\"><h1>no se puede dividir por cero!</h1></div></p>");
}
}
if(op.equals("*"))
{
double res=n1*n2;
out.print("<h1>"+n1+"*"+n2+"="+ res + "</h1>");
}
}
}
catch(java.lang.NumberFormatException error)
{
out.print("<p><div id=\"error\"><h1>Solo ingresar numeros</h1></div></p>");
}
%>
</body>
</html>
---------------------------------------------------------------------
Este seria el codigo css(muy basico)
table
{
background-color:#FFFF22;
align="center"
margin: 0 auto;
}
#error
{
color:red;
margin: 0 auto;
}