📄 j-scjp-9-1.html
字号:
<td class="small" colspan="6"><a target="_blank" style="color: #ffffff;" href="http://202.95.2.149/help.htm">高级搜索</a><img alt="" height="1" width="1" border="0" src="../i/c.gif"></td>
</tr>
<tr>
<td colspan="6"><img alt="" height="4" width="390" border="0" src="../i/c.gif"></td>
</tr>
</form>
</table>
</td>
</tr>
<tr>
<td class="hbg" height="21" width="160"></td><td class="bbg" valign="top" height="21" colspan="2"> <a href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/" class="mainlink">IBM 主页</a><span class="divider"> | </span><a href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/products/index.shtml" class="mainlink">产品与服务</a><span class="divider"> | </span><a href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/support/index.shtml" class="mainlink">支持与下载</a><span class="divider"> | </span><a href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/account/index.shtml" class="mainlink">个性化服务</a></td>
</tr>
</table>
<TABLE width="100%" cellspacing="0" cellpadding="0" border="0">
<TR>
<TD bgcolor="#ffffff" height="1" width="150"><IMG src="../i/c.gif" width="150" height="1"></TD>
</TR>
<TR>
<TD bgcolor="#cc6633" height="3" width="150"><IMG src="../i/c.gif" width="150" height="3"></TD>
</TR>
<TR>
<TD bgcolor="#333333" height="1" width="150"><IMG src="../i/c.gif" width="150" height="1"></TD>
</TR>
<TR>
<TD bgcolor="#000000" height="1" width="150"><IMG src="../i/c.gif" width="150" height="1"></TD>
</TR>
<TR>
<TD bgcolor="#ffffff" height="1" width="150"><IMG src="../i/c.gif" width="150" height="2"></TD>
</TR>
</TABLE>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><font size="-1" face="Verdana, sans-serif"><a href="http://www.ibm.com/">IBM</a> : <a href="/developerWorks/cn/index.shtml">developerWorks 中国网站</a> : <a href="/developerWorks/cn/java/index.shtml">java</a> : <a href="/developerWorks/cn/cnedu.nsf/java-onlinecourse-bytitle?OpenView&Count=500">教学 - 在线教程</a></font>
<br>
<img alt=" Java 认证成功之路,第 1 部分:SCJP " src="imagemaster/masthead.jpg"></td><td width="*" valign="bottom" align="right"><a border="0" href="j-scjp.zip"><img alt="下载 ZIP 文件" border="0" src="../i/icon-zip.gif"></a><a target="_blank" href="../tutorial_eng/index.html" border="0"><img alt="英文原文" border="0" src="../i/icon-source.gif"></a>
</td>
</tr>
<tr>
<td height="2" colspan="2"><img height="2" width="1" src="../i/c.gif"></td>
</tr>
</table>
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
<TR>
<TD width="150" height="1" bgcolor="#000000" colspan="6"><IMG alt="" height="1" width="150" src="../i/c.gif"></TD>
</TR>
<TR>
<TD background="../i/sw-gold.gif"><a border="0" href="index.html" onMouseOver="iOver('topmain'); iOver('bottommain'); self.status=mainblurb; return true;" onMouseOut="iOut('topmain'); iOut('bottommain'); self.status=''; return true;"><img alt="主菜单" border="0" src="../i/main.gif" name="topmain"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topsection'); iOver('bottomsection'); self.status=sectionblurb; return true;" onMouseOut="iOut('topsection'); iOut('bottomsection'); self.status=''; return true;" href="index9.html"><img alt="章节菜单" border="0" src="../i/section.gif" name="topsection"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topfeedback'); iOver('bottomfeedback'); self.status=feedbackblurb; return true;" onMouseOut="iOut('topfeedback'); iOut('bottomfeedback'); self.status=''; return true;" href="j-scjp-11-3.html"><img alt="给出此教程的反馈意见" border="0" src="../i/feedback.gif" name="topfeedback"></a></TD><TD width="100%" background="../i/sw-gold.gif"><img src="../i/c.gif"></TD><TD background="../i/sw-gold.gif"><img border="0" src="../i/xprevious.gif"></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topnext'); iOver('bottomnext'); self.status=nextblurb; return true;" onMouseOut="iOut('topnext'); iOut('bottomnext'); self.status=''; return true;" href="j-scjp-9-2.html"><img alt="下页" border="0" src="../i/next.gif" name="topnext"></a></TD>
</TR>
</TABLE>
<table bgcolor="ffffff" cellspacing="0" cellpadding="2" border="0" height="400" width="100%">
<tr valign="bottom">
<a name="navskip"></a><td height="25" colspan="4"><img alt="9.java.lang 包中的基本类 " src="imagemaster/titlebar9.jpg" border="0" height="25" width="562"></td>
</tr>
<tr>
<td bgcolor="ffffff" width="15"> </td><td bgcolor="ffffff" width="12"> </td><td valign="top" align="left" bgcolor="ffffff" width="*">
<p>
<br>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="90%"><font size="4" face="Verdana, Arial, Helvetica"><b>使用 Math 类 </b></font></td><td width="200" align="right"><font size="1" face="Verdana, Arial, Helvetica"><nobr> 第 1 页(共5 页)</nobr></font></td>
</tr>
</table>
<br>
<br>
</p>
<font size="2" face="Verdana, Arial, Helvetica">
<p>
<code>Math</code> 类是 <code>final</code> 的,并且在 <code>Math</code> 类中定义的所有方法都是 <code> static </code>,这意味着不能继承 <code>Math</code> 类并覆盖这些方法。同时, <code>Math</code> 类有一个私有构造函数,所以不能实例化它。 </p>
<p>
<code>Math</code> 类有以下方法: <code>ceil()</code>、 <code>floor()</code>、 <code>max()</code>、 <code>min()</code>、 <code>random()</code>、 <code>abs()</code>、 <code>round()</code>、 <code>sin()</code>、 <code>cos()</code>、 <code>tan()</code> 和 <code>sqrt()</code>。</p>
<p>
<code>ceil()</code> 方法返回不小于参数并且等于一个数学整数的最小双精度值。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
Math.ceil(5.4) // gives 6
Math.ceil(-6.3) // gives -6
</code>
</pre>
<p>
<code>floor()</code> 方法返回不大于参数并等于一个数学整数的最大双精度值。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
Math.floor(5.4) // gives 5
Math.floor(-6.3) // gives -7
</code>
</pre>
<p>
<code>max()</code> 方法有两个数字参数并返回其中较大者。它对于 <code>int</code>、 <code>long</code>、 <code>float</code> 或者 <code>double</code> 参数进行了重载。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
x = Math.max(10,-10); // returns 10
</code>
</pre>
<p>
<code>min</code> 方法有两个数字参数并返回其中的较小者。它对于 <code>int</code>、 <code>long</code>、 <code>float</code> 或者 <code>double</code> 参数进行了重载。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
x = Math.min(10,-10); // returns -10
</code>
</pre>
<p>
<code>random()</code> 方法返回一个具有正号、大于或等于 0.0 并小于 1.0 的双精度值。 </p>
<p>
<code>abs()</code> 方法返回参数的绝对值。它对于 <code>int</code>、 <code>long</code>、 <code>float</code> 或者 <code>double</code> 参数进行了重载。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
Math.abs(-33) // returns 33
</code>
</pre>
<p>
<code>round()</code> 方法返回最接近于参数的整数(对 <code>float</code> 和 <code>double</code> 参数重载)。如果小数点后的数字小于0.5,那么 <code>Math.round()</code> 返回与 <code>Math.floor()</code>同样的结果。在其他情况下, <code>Math.round()</code> 与 <code>Math.ceil()</code> 的结果一样。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
Math.round(-1.5) // result is -1
Math.round(1.8) // result is 2
</code>
</pre>
<p>
<b>三角函数 </b>
<br>
<code>sin()</code>、 <code>cos()</code> 和 <code>tan()</code> 法分别返回一个角度的正弦、余弦和正切。在这三种方法中,参数都是以弧度为单位的角度。度数可以用 <code>Math.toRadians()</code>转换为弧度。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
x = Math.sin(Math.toRadians(90.0)); // returns 1.0
</code>
</pre>
<p>
<code>sqrt()</code> 函数返回类型为 <code>double</code> 的参数的平方根。例如: </p>
<pre>
<code style="font-family: Courier New, Courier, monospace; font-size: 12">
x = Math.sqrt(25.0); // returns 5.0
</code>
</pre>
<p>如果向 <code>sqrt()</code> 函数传递负数,那么它返回 <code>NaN</code> (“不是一个数字”)。 </p>
<br>
</font></td>
</tr>
</table>
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
<TR>
<TD background="../i/sw-gold.gif"><a border="0" href="index.html" onMouseOver="iOver('topmain'); iOver('bottommain'); self.status=mainblurb; return true;" onMouseOut="iOut('topmain'); iOut('bottommain'); self.status=''; return true;"><img alt="主菜单" border="0" src="../i/main.gif" name="bottommain"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topsection'); iOver('bottomsection'); self.status=sectionblurb; return true;" onMouseOut="iOut('topsection'); iOut('bottomsection'); self.status=''; return true;" href="index9.html"><img alt="章节菜单" border="0" src="../i/section.gif" name="bottomsection"></a></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topfeedback'); iOver('bottomfeedback'); self.status=feedbackblurb; return true;" onMouseOut="iOut('topfeedback'); iOut('bottomfeedback'); self.status=''; return true;" href="j-scjp-11-3.html"><img alt="给出此教程的反馈意见" border="0" src="../i/feedback.gif" name="bottomfeedback"></a></TD><TD width="100%" background="../i/sw-gold.gif"><img src="../i/c.gif"></TD><TD background="../i/sw-gold.gif"><img border="0" src="../i/xprevious.gif"></TD><TD background="../i/sw-gold.gif"><a border="0" onMouseOver="iOver('topnext'); iOver('bottomnext'); self.status=nextblurb; return true;" onMouseOut="iOut('topnext'); iOut('bottomnext'); self.status=''; return true;" href="j-scjp-9-2.html"><img alt="下页" border="0" src="../i/next.gif" name="bottomnext"></a></TD>
</TR>
<TR>
<TD width="150" height="1" bgcolor="#000000" colspan="6"><IMG alt="" height="1" width="150" src="../i/c.gif"></TD>
</TR>
</TABLE>
<TABLE width="100%" cellpadding="0" cellspacing="0" border="0">
<TR>
<TD width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img alt="" height="1" width="1" src="../i/c.gif"></td>
</tr>
<tr valign="top">
<td class="bbg" height="21"> <a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/index.shtml">关于 IBM</a><span class="divider"> | </span><a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/privacy/index.shtml">隐私条约</a><span class="divider"> | </span><a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/legal/index.shtml">法律条款</a><span class="divider"> | </span><a class="mainlink" href="/developerWorks/cgi-bin/click.cgi?url=http://www-900.ibm.com/cn/ibm/contact/index.shtml">联系 IBM</a></td>
</tr>
</table>
</TD>
</TR>
</TABLE>
<script src="//www.ibm.com/common/stats/stats.js" language="JavaScript1.2" type="text/javascript"></script>
<noscript>
<img border="0" alt="" height="1" width="1" src="//stats.www.ibm.com/rc/images/uc.GIF?R=noscript"></noscript>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -