<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeMocha</title>
	<atom:link href="http://codemocha.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codemocha.com</link>
	<description>Freshly ground code.  Thoughts on software and algorithms by Chet Mancini</description>
	<lastBuildDate>Fri, 18 Sep 2009 15:22:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Count Lines of Java Code Across Packages</title>
		<link>http://codemocha.com/2009/09/count-lines-of-java-code-across-packages/</link>
		<comments>http://codemocha.com/2009/09/count-lines-of-java-code-across-packages/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 15:22:50 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=33</guid>
		<description><![CDATA[This little command will add up the lines of code across packages in a Java program.
1find . -name &#34;*.java&#34; -exec wc -l {} \+
]]></description>
			<content:encoded><![CDATA[<p>This little command will add up the lines of code across packages in a Java program.</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br /></div></td><td><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">find . -name &quot;*.java&quot; -exec wc -l {} \+</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/09/count-lines-of-java-code-across-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Browsers, Part 1</title>
		<link>http://codemocha.com/2009/07/browsers-part-1/</link>
		<comments>http://codemocha.com/2009/07/browsers-part-1/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 02:43:03 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=31</guid>
		<description><![CDATA[When I owned my first computer there were two well known choice: Internet Explorer and Netscape.  IE won and for about a year thats all I used.  I tinkered around with Mozilla (this is the old Mozilla suite), but found it less polished and it tried to do everything.

I discovered a new browser [...]]]></description>
			<content:encoded><![CDATA[<p>When I owned my first computer there were two well known choice: Internet Explorer and Netscape.  IE won and for about a year thats all I used.  I tinkered around with Mozilla (this is the old Mozilla suite), but found it less polished and it tried to do everything.<br />
<span id="more-31"></span><br />
I discovered a new browser called Firebird.  It had been previously released as Phoenix, but the name was changed.  I loved it.  It was so slick, so fast, so compatible.  There were cool plugins and search features.  Every .1 version upgrade I dutifully reinstalled flash, Java, and the other plugins needed to make it work with rich content.  We take all this automation for granted now, but upgrading Firebird was an involved process, and I even wrote tutorials for others on how to get it working.</p>
<p>I hated the name Firefox initially, but it grew on me because I loved the browser so much.  I made a Firefox cake for the 1.0 release (and ate it myself).  I had Firefox wallpaper and custom Firefox icons (though I still like the original logo).  I used Thunderbird and Sunbird for my email and calendars.  I called it early.  Firefox became big and the Suite, what I believe was later named Seamonkey, vanished.  I shed few tears, as I wanted stripped-down browsing.</p>
<p>I did everything to juice out speed.  I kept only the most essential extensions&#8211;like Web Developer and the original Adblock.  I later installed FasterFox which opened additional connections to get data faster.  Those were great days, and how I browsed until about three years ago.</p>
<p>To be continued.</p>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/07/browsers-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beatitudes in C#</title>
		<link>http://codemocha.com/2009/07/beatitudes-in-c/</link>
		<comments>http://codemocha.com/2009/07/beatitudes-in-c/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 01:26:04 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[humor]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=29</guid>
		<description><![CDATA[12345678class the_earth
&#123;
...
&#125;;
class the_meek : public the_earth
&#123;
...
&#125;;
From: StackOverflow answer
]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="csharp codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw4">class</span> the_earth<br />
<span class="br0">&#123;</span><br />
...<br />
<span class="br0">&#125;</span><span class="sy0">;</span><br />
<span class="kw4">class</span> the_meek <span class="sy0">:</span> <span class="kw1">public</span> the_earth<br />
<span class="br0">&#123;</span><br />
...<br />
<span class="br0">&#125;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>From: <a href="http://stackoverflow.com/questions/660972/what-is-your-best-pseudo-code-phrase/664411#664411">StackOverflow answer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/07/beatitudes-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bit Operations</title>
		<link>http://codemocha.com/2009/07/bit-operations/</link>
		<comments>http://codemocha.com/2009/07/bit-operations/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 18:31:41 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[bits]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=22</guid>
		<description><![CDATA[For CS351, Intro to Systems, we had to do several operations using bit operators only.  These took awhile, but are pretty cool to show off.  We were graded by how few operations we used to return the right values for the generated test cases, including some difficult boundary ones.
1234//NOR operation using only ~ [...]]]></description>
			<content:encoded><![CDATA[<p>For CS351, Intro to Systems, we had to do several operations using bit operators only.  These took awhile, but are pretty cool to show off.  We were graded by how few operations we used to return the right values for the generated test cases, including some difficult boundary ones.<span id="more-22"></span></p>
<div class="codecolorer-container c vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="c codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">//NOR operation using only ~ and &amp;</span><br />
<span class="kw4">int</span> bitNor<span class="br0">&#40;</span><span class="kw4">int</span> x<span class="sy0">,</span> <span class="kw4">int</span> y<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>~x<span class="br0">&#41;</span><span class="sy0">&amp;</span><span class="br0">&#40;</span>~y<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>The XOR operation is equivalent to the (x NAND y) AND (x OR y).</p>
<div class="codecolorer-container c vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="c codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">//XOR operation using only ~ and &amp;</span><br />
<span class="kw4">int</span> bitXor<span class="br0">&#40;</span><span class="kw4">int</span> x<span class="sy0">,</span> <span class="kw4">int</span> y<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>~<span class="br0">&#40;</span>x<span class="sy0">&amp;</span>y<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">&amp;</span><span class="br0">&#40;</span>~<span class="br0">&#40;</span><span class="br0">&#40;</span>~x<span class="br0">&#41;</span><span class="sy0">&amp;</span><span class="br0">&#40;</span>~y<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container c vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="c codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="co1">//Return true if x is not equal to y not using comparison operators.</span><br />
<span class="kw4">int</span> isNotEqual<span class="br0">&#40;</span><span class="kw4">int</span> x<span class="sy0">,</span> <span class="kw4">int</span> y<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="sy0">!!</span><span class="br0">&#40;</span>x<span class="sy0">^</span>y<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>There are two types of shifts, arithmetic and logical.  Left shifts are the same in both types, but right shifts are different.  Logical shifts insert zeroes to fill in the empty spaces to keep the logic of the bits, but arithmetic shifts fill in the value of the sign bit to preserve the sign of the operand in twos-complement integers.</p>
<div class="codecolorer-container c vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="c codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw4">int</span> rightLogicalShift<span class="br0">&#40;</span><span class="kw4">int</span> x<span class="sy0">,</span> <span class="kw4">int</span> n<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> allOnes <span class="sy0">=</span> ~<span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> y <span class="sy0">=</span> ~<span class="br0">&#40;</span><span class="br0">&#40;</span>allOnes<span class="br0">&#41;</span> <span class="sy0">&lt;&lt;</span> <span class="br0">&#40;</span><span class="nu0">32</span> <span class="sy0">+</span> <span class="br0">&#40;</span>~n <span class="sy0">+</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span><span class="br0">&#40;</span>x <span class="sy0">&gt;&gt;</span> n<span class="br0">&#41;</span> <span class="sy0">&amp;</span> y<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/07/bit-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Euclidean Algorithm</title>
		<link>http://codemocha.com/2009/07/euclidean-algorithm/</link>
		<comments>http://codemocha.com/2009/07/euclidean-algorithm/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 03:46:41 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[ml]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=9</guid>
		<description><![CDATA[One of my favorite algorithms is the simple, elegant Euclidean algorithm for finding the greatest common denominator of two numbers.  In ML or another functional language it really is beautiful:
12fun gcd&#40;a, 0&#41; = a
&#160; &#160;&#124; gcd&#40;a, b&#41; = gcd&#40;b, a mod b&#41;;
Of course, the same can be done in Java iteratively:
123456789public int gcd&#40;int a, [...]]]></description>
			<content:encoded><![CDATA[<p>One of my favorite algorithms is the simple, elegant Euclidean algorithm for finding the greatest common denominator of two numbers.  In ML or another functional language it really is beautiful:<span id="more-9"></span></p>
<div class="codecolorer-container ocaml vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br /></div></td><td><div class="ocaml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">fun</span> gcd<span class="br0">&#40;</span>a, <span class="nu0">0</span><span class="br0">&#41;</span> <span class="sy0">=</span> a<br />
&nbsp; &nbsp;<span class="sy0">|</span> gcd<span class="br0">&#40;</span>a, b<span class="br0">&#41;</span> <span class="sy0">=</span> gcd<span class="br0">&#40;</span>b, a <span class="kw1">mod</span> b<span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
<p>Of course, the same can be done in Java iteratively:</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">int</span> gcd<span class="br0">&#40;</span><span class="kw4">int</span> a, <span class="kw4">int</span> b<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw4">int</span> c<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span>b<span class="sy0">&gt;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; c <span class="sy0">=</span> a<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; a <span class="sy0">=</span> b<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; b <span class="sy0">=</span> c<span class="sy0">%</span>b<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> a<span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
<p>Or recursively:</p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">public</span> <span class="kw4">int</span> gcd<span class="br0">&#40;</span><span class="kw4">int</span> a, <span class="kw4">int</span> b<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>b<span class="sy0">==</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> a<span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> gcd<span class="br0">&#40;</span>b, a<span class="sy0">%</span>b<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/07/euclidean-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursive Fibonacci</title>
		<link>http://codemocha.com/2009/07/recursive-fibonacci/</link>
		<comments>http://codemocha.com/2009/07/recursive-fibonacci/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 03:40:28 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[college]]></category>
		<category><![CDATA[fibonacci]]></category>
		<category><![CDATA[ml]]></category>
		<category><![CDATA[recusion]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=7</guid>
		<description><![CDATA[Here are two recursive fibonacci functions in ML I did for CS243.  Can you tell which one is more efficient?
123456789101112fun fibonacci&#40;n&#41; = 
&#160; let
&#160; &#160; &#160; fun fib&#40;&#40;a, b&#41;, i&#41;= &#160;
&#160; &#160; if i=0 then b
&#160; &#160; &#160; &#160; else fib&#40;&#40;b, a + b&#41;, i-1&#41;;
&#160; &#160; &#160; &#160; &#160; &#160;in
&#160; fib&#40;&#40;0, 1&#41;, n&#41;
&#160; end;

fun [...]]]></description>
			<content:encoded><![CDATA[<p>Here are two recursive fibonacci functions in ML I did for CS243.  Can you tell which one is more efficient?<span id="more-7"></span></p>
<div class="codecolorer-container ocaml vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="ocaml codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">fun</span> fibonacci<span class="br0">&#40;</span>n<span class="br0">&#41;</span> <span class="sy0">=</span> <br />
&nbsp; <span class="kw1">let</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">fun</span> fib<span class="br0">&#40;</span><span class="br0">&#40;</span>a, b<span class="br0">&#41;</span>, i<span class="br0">&#41;</span><span class="sy0">=</span> &nbsp;<br />
&nbsp; &nbsp; <span class="kw1">if</span> i<span class="sy0">=</span><span class="nu0">0</span> <span class="kw1">then</span> b<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> fib<span class="br0">&#40;</span><span class="br0">&#40;</span>b, a <span class="sy0">+</span> b<span class="br0">&#41;</span>, i<span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">in</span><br />
&nbsp; fib<span class="br0">&#40;</span><span class="br0">&#40;</span><span class="nu0">0</span>, <span class="nu0">1</span><span class="br0">&#41;</span>, n<span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">end</span><span class="sy0">;</span><br />
<br />
<span class="kw1">fun</span> fibonacci<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="nu0">1</span><br />
&nbsp; <span class="sy0">|</span> fibonacci<span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">=</span> <span class="nu0">1</span><br />
&nbsp; <span class="sy0">|</span> fibonacci<span class="br0">&#40;</span>n<span class="br0">&#41;</span> <span class="sy0">=</span> fibonacci<span class="br0">&#40;</span>n<span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span> <span class="sy0">+</span> fibonacci<span class="br0">&#40;</span>n<span class="sy0">-</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/07/recursive-fibonacci/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Circle Calculator</title>
		<link>http://codemocha.com/2009/07/circle-calculator/</link>
		<comments>http://codemocha.com/2009/07/circle-calculator/#comments</comments>
		<pubDate>Sat, 04 Jul 2009 03:26:57 +0000</pubDate>
		<dc:creator>Chet</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[calculator]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[college]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://codemocha.com/?p=3</guid>
		<description><![CDATA[For my first code post I thought it might be appropriate to put the first code from the first lab of my first computer science class at Wheaton.]]></description>
			<content:encoded><![CDATA[<p>For my first code post I thought it might be appropriate to put the first code from the first lab of my first computer science class at Wheaton.<span id="more-3"></span></p>
<div class="codecolorer-container java vibrant" style="overflow:auto;white-space:nowrap;width:600px"><table cellspacing="0" cellpadding="0"><tbody><tr><td class="line-numbers"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">import</span> <span class="co2">java.util.Scanner</span><span class="sy0">;</span><br />
<span class="kw1">public</span> <span class="kw1">class</span> Circle <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">void</span> main<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">String</span></a><span class="br0">&#91;</span><span class="br0">&#93;</span> args<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Scanner keyboard <span class="sy0">=</span> <span class="kw1">new</span> Scanner<span class="br0">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">in</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp;<span class="co1">// input from keyboard</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">print</span><span class="br0">&#40;</span><span class="st0">&quot;Please enter the radius--&gt;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> radius <span class="sy0">=</span> keyboard.<span class="me1">nextDouble</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp; <span class="co1">// radius to work with</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> diameter <span class="sy0">=</span> radius<span class="sy0">*</span><span class="nu0">2</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;The diameter is &quot;</span> <span class="sy0">+</span> diameter<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> circumference <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">PI</span><span class="sy0">*</span><span class="nu0">2</span><span class="sy0">*</span>radius<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;The circumference is &quot;</span> <span class="sy0">+</span> circumference<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> area <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">PI</span> <span class="sy0">*</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">pow</span><span class="br0">&#40;</span>radius, <span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;The area is &quot;</span> <span class="sy0">+</span> area<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> volume <span class="sy0">=</span> <span class="br0">&#40;</span><span class="nu0">4.0</span> <span class="sy0">/</span> <span class="nu0">3.0</span><span class="br0">&#41;</span> <span class="sy0">*</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">PI</span> <span class="sy0">*</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">pow</span><span class="br0">&#40;</span>radius, <span class="nu0">3</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;The volume of a sphere is &quot;</span> <span class="sy0">+</span> volume<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">double</span> surfaceArea <span class="sy0">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">PI</span> <span class="sy0">*</span> <span class="nu0">4</span> <span class="sy0">*</span> &nbsp;<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amath+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">Math</span></a>.<span class="me1">pow</span><span class="br0">&#40;</span>radius, <span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span class="kw3">System</span></a>.<span class="me1">out</span>.<span class="me1">println</span><span class="br0">&#40;</span><span class="st0">&quot;The surface area of a sphere is &quot;</span> <span class="sy0">+</span> surfaceArea<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://codemocha.com/2009/07/circle-calculator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
