四则运算2
Posted 天明宝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四则运算2相关的知识,希望对你有一定的参考价值。
1设计思想
本题四则运算需要满足加减法在100以内,乘除法满足九九运算表,使用java文件判断是否满足加减法条件,利用javascript计时器来计时。
2源程序代码
仅写java及jsp文件
1 package com.sizeuser.msg.calculate; 2 public interface Calculate { 3 public int add(int add1,int add2); 4 public int subtraction(int subtract1,int subtract2); 5 public int multiply(int multiply1,int multiply2); 6 public int divid(int dividend,int divid); 7 }
1 package com.sizeuser.msg.calculate; 2 3 import java.util.Random; 4 5 import org.apache.jasper.tagplugins.jstl.core.Out; 6 7 import com.sun.org.apache.bcel.internal.generic.ReturnaddressType; 8 9 public class CalculateImpl implements Calculate{ 10 static Random random=new Random(); 11 @Override 12 public int add(int add1, int add2) { 13 int sum; 14 if(add1+add2<=100&&add1+add2>0) 15 { 16 sum=add1+add2; 17 return sum; 18 } 19 return 0; 20 } 21 @Override 22 public int subtraction(int subtract1, int subtract2) { 23 int sum; 24 if(subtract1-subtract2>0) 25 { 26 sum=subtract1-subtract2; 27 return sum; 28 } 29 return 0; 30 } 31 @Override 32 public int multiply(int multiply1, int multiply2) { 33 if(multiply1>0&&multiply1<=9&&multiply2>0&&multiply2<=9) 34 { 35 return multiply1*multiply2; 36 } 37 return 0; 38 } 39 @Override 40 public int divid(int dividend, int divid) { 41 if (dividend>0&÷nd<=81&&divid>0&&divid<=9&÷nd%divid==0&÷nd/divid>0&÷nd/divid<9) 42 { 43 return dividend/divid; 44 } 45 return 0; 46 } 47 48 public static void main(String []args) 49 { 50 51 } 52 }
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <script type="text/javascript"> 7 var t; 8 var c=0; 9 //全局变量 10 function timedCount() 11 { 12 13 document.getElementById("num").style.display="none"; 14 document.getElementById("jishi").style.display="none"; 15 var txtobj=document.getElementById("num"); 16 var sum=parseInt(txtobj.value)*60; 17 var sum1=sum-c; 18 //秒 19 var hour=parseInt(sum1/3600); 20 var minute=parseInt(sum1/60%60); 21 if(minute==60||minute<1) 22 minute=0; 23 var lastsecs=parseInt(sum1%60); 24 lastsecs=lastsecs<10?\'0\'+lastsecs:lastsecs; 25 minute=minute<10?\'0\'+minute:minute; 26 hour=hour<10?\'0\'+hour:hour; 27 c++; 28 document.getElementById("result").innerHTML=hour+":"+minute+":"+lastsecs; 29 t=setTimeout("timedCount()",1000); 30 if(sum1==0) 31 { 32 clearTimeout(t); 33 alert("时间到!"); 34 } 35 } 36 </script> 37 </head> 38 <body> 39 <form> 40 41 <input type = "text" id = "num" > 42 <input type="button" id="jishi" value="开始计时!/分" onClick="timedCount()"> 43 <p id="result"> 44 </p> 45 </form> 46 </body> 47 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 你好
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <html> 4 <%@include file="header.jsp" %> 5 <hr> 6 <form action="sanze.jsp" method="get"> 7 8 请输入混合运算的数量:<input type="text" name="num"/><br> 9 请输入做题时间:<input type="text" name="time" /><br> 10 <input type="submit" value="提交" /> 11 </form> 12 </html>
1 <%@page import="com.sizeuser.msg.calculate.CalculateImpl"%> 2 <%@page import="com.sizeuser.msg.calculate.Calculate"%> 3 <%@page import="java.util.Random"%> 4 <%@ page language="java" contentType="text/html; charset=UTF-8" 5 pageEncoding="UTF-8"%> 6 <form action="show.jsp" method="get"/> 7 <head> 8 <% 9 String time=request.getParameter("time"); 10 %> 11 <script type="text/javascript"> 12 var t; 13 var c=0; 14 //全局变量 15 function timedCount() 16 { 17 var txtobj=<%=time%>; 18 var sum=parseInt(txtobj)*60; 19 var sum1=sum-c; 20 //秒 21 var hour=parseInt(sum1/3600); 22 var minute=parseInt(sum1/60%60); 23 if(minute==60||minute<1) 24 minute=0; 25 var lastsecs=parseInt(sum1%60); 26 lastsecs=lastsecs<10?\'0\'+lastsecs:lastsecs; 27 minute=minute<10?\'0\'+minute:minute; 28 hour=hour<10?\'0\'+hour:hour; 29 c++; 30 document.getElementById("result").innerHTML=hour+":"+minute+":"+lastsecs; 31 t=setTimeout("timedCount()",1000); 32 if(sum1==0) 33 { 34 clearTimeout(t); 35 alert("小朋友,答题时间结束了哦!"); 36 document.getElementById("anniu").click(); 37 } 38 } 39 </script> 40 </head> 41 <body onLoad="timedCount()";> 42 <p id="result"> 43 </p> 44 Java基础知识 自增自减运算符获取 badarith,[erlang,'+',[error,0],[],同时使用 Erlang 片段在 TSUNG 中执行算术运算