重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
//自定义 Math 类brvar MyMath=(function(){br
创新互联是一家专注于网站制作、网站建设与策划设计,囊谦网站建设哪家好?创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:囊谦等地区。囊谦做网站价格咨询:13518219792
var diff=0.00000000001; //精度br
var GetSqrt= function(n){ br
var s = n / 2; //假设的平方根初值 br
while (NotFit(s,n)) { br
s = ((n / s) + s) / 2;br
} br
return s; br
},NotFit=function( num, n){ br
var r= num*num; br
var d = Abs(n - Abs(r)); br
if(ddiff){ br
return true; br
}br
return false; br
},Abs=function(a){br
if(a=0 )return a;br
else return -a;br
}; brbr
return {br
sqrt:GetSqrt,br
abs:Absbr
};br})();brbr//sqrtbralert(MyMath.sqrt(0));//0bralert(MyMath.sqrt(1));//1bralert(MyMath.sqrt(9));//3brbr//absbralert(MyMath.abs(-4));//4上面的代码自己测试可以运行
%@ page language="java" import="java.util.*" pageEncoding="gb2312"%
%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
base href="%=basePath%"
titleMy JSP 'index.jsp' starting page/title
meta http-equiv="pragma" content="no-cache"
meta http-equiv="cache-control" content="no-cache"
meta http-equiv="expires" content="0"
meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
meta http-equiv="description" content="This is my page"
!--
link rel="stylesheet" type="text/css" href="styles.css"
--
script type="text/javascript"
function getById(id){
return document.getElementById(id);
}
function getInfo(){
var num=getById("num").value;
if(isNaN(num) || num1){
alert("请输入正整数!");
}else{
alert(num+"的平方值为:"+num*num);
alert(num+"的平方根为:"+Math.sqrt(num));
}
}
/script
/head
body
input type="text" size="20" id="num"input type="button" value="计算" onclick="getInfo()"
/body
/html
楼主,望采纳啊,^_^,给点评价哦 ,可以结贴了。绝对没问题
s="";
for(var i=5; i16; i++){
s+=i+" "+Math.pow(i,2)+" "+Math.pow(i,3)+"\n";
}
alert(s);
%@page contentType="text/html;charset=gbk" %
html
head
script
function show(){
var maxRow =10;
var strTbl = "table border='1'tbody";
var strTbody = "";
strTbody+="tr align='center'th给定数字/thth平方值/thth立方值/thtr";
for(var i = 0; i =maxRow; i++){
strTbody +="tr align='center'";
strTbody+="td"+i+"/tdtd"+i*i+"/tdtd"+i*i*i+"/td";
strTbody += "/tr";
}
strTbl = strTbody + "/tbody/table";
document.getElementById("tableDiv").innerHTML = strTbl;
}
/script
/head
body onload="show()"
div id="tableDiv"/div
/body
/html
前面求值你应该会
给你写一下百位以下
html
script
var a=123;
var b=String(a);
var d=b.length;
var c=b.substring(d-2,d);
alert(c);
/script
/html