﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Java Home-随笔分类-JAVA个人敝作</title><link>http://www.blogjava.net/yemoo/category/12203.html</link><description>Java技术修炼中...</description><language>zh-cn</language><lastBuildDate>Thu, 01 Mar 2007 02:32:53 GMT</lastBuildDate><pubDate>Thu, 01 Mar 2007 02:32:53 GMT</pubDate><ttl>60</ttl><item><title>八进制转十进制【限制int范围内】</title><link>http://www.blogjava.net/yemoo/archive/2006/12/05/85530.html</link><dc:creator>Yemoo'S Java Blog</dc:creator><author>Yemoo'S Java Blog</author><pubDate>Tue, 05 Dec 2006 03:34:00 GMT</pubDate><guid>http://www.blogjava.net/yemoo/archive/2006/12/05/85530.html</guid><wfw:comment>http://www.blogjava.net/yemoo/comments/85530.html</wfw:comment><comments>http://www.blogjava.net/yemoo/archive/2006/12/05/85530.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/yemoo/comments/commentRss/85530.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/yemoo/services/trackbacks/85530.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008000">/**</span>
				<span style="COLOR: #008000">
						<br /> *Description:convert Oct to Dec<br /> *Author:yemoo 2006.12.05<br /> </span>
				<span style="COLOR: #008000">*/</span>
				<span style="COLOR: #000000">
						<br />
						<br /> </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> P38{<br />     </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> convertOct2Dec(String Oct){<br />         </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> result</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />         </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> power</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br />         </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000">(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> i</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">Oct.length()</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;i</span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;i</span>
				<span style="COLOR: #000000">--</span>
				<span style="COLOR: #000000">,power</span>
				<span style="COLOR: #000000">*=</span>
				<span style="COLOR: #000000">8</span>
				<span style="COLOR: #000000">){<br />             </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> temp</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">Oct.charAt(i);<br />             </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> intTemp</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">Character.getNumericValue(temp);<br />             </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(intTemp</span>
				<span style="COLOR: #000000">&gt;=</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000">intTemp</span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">8</span>
				<span style="COLOR: #000000">){<br />                 result</span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000">intTemp</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">power;<br />             }</span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />                 </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000">(temp</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">'</span>
				<span style="COLOR: #000000">&amp;&amp;</span>
				<span style="COLOR: #000000">i</span>
				<span style="COLOR: #000000">==</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">){<br />                     result</span>
				<span style="COLOR: #000000">=-</span>
				<span style="COLOR: #000000">result;<br />                 }</span>
				<span style="COLOR: #0000ff">else</span>
				<span style="COLOR: #000000">{<br />                     </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> result;<br />                 }<br />             }<br />         }<br />         </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> result;<br />     }<br /><br />     String readInput(){<br />         KeyboardInput in</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> KeyboardInput();<br />         System.out.print(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Please input a october number:</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />         </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> in.readString();<br />     }<br /><br />     </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> main(String args[]){<br />         P38 obj</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> P38();<br />         String oct</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">obj.readInput();<br />         </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> value</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">obj.convertOct2Dec(oct);<br />         System.out.println(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Oct:</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">oct</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">==Dec:</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">+</span>
				<span style="COLOR: #000000">value);<br />     }<br /> }</span>
		</div>
<img src ="http://www.blogjava.net/yemoo/aggbug/85530.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/yemoo/" target="_blank">Yemoo'S Java Blog</a> 2006-12-05 11:34 <a href="http://www.blogjava.net/yemoo/archive/2006/12/05/85530.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>