<?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>java code Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/java-code/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/java-code/</link>
	<description>Code Solution</description>
	<lastBuildDate>Sat, 17 Oct 2020 06:53:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>java code Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/java-code/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Create Basic Calculator Program with Java</title>
		<link>https://codeplaners.com/how-to-create-basic-calculator-program-with-java/</link>
					<comments>https://codeplaners.com/how-to-create-basic-calculator-program-with-java/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 17 Oct 2020 06:53:59 +0000</pubDate>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[calculator]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java calculator]]></category>
		<category><![CDATA[java code]]></category>
		<guid isPermaLink="false">http://localhost/codeplaners/?p=303</guid>

					<description><![CDATA[<p>Introduction  In this code, we build a simple calculator based on the user &#8216;s input that performs addition , subtraction , multiplication and division. The code takes the value of both numbers (entered by the user) and then allows the user to enter the operation (+,-, * and /), which is based on the input &#8230; <a href="https://codeplaners.com/how-to-create-basic-calculator-program-with-java/" class="more-link">Continue reading<span class="screen-reader-text"> "How to Create Basic Calculator Program with Java"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-create-basic-calculator-program-with-java/">How to Create Basic Calculator Program with Java</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>Introduction </strong><br />
In this code, we build a simple calculator based on the user &#8216;s input that performs addition , subtraction , multiplication and division. The code takes the value of both numbers (entered by the user) and then allows the user to enter the operation (+,-, * and /), which is based on the input programme that performs the selected operation using the switch case on the tried to enter numbers.</p>
<p><strong>Step 1)</strong> Java Calculator with Source Code: With the help of AWT / Swing with event handling, we can create a Java calculator. Let &#8216;s look at the calculator development code in Java.</p>
<pre><code class="java hljs"><span class="hljs-keyword">import</span> java.util.Scanner;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calculator</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        Scanner reader = <span class="hljs-keyword">new</span> Scanner(System.in);
        System.out.print(<span class="hljs-string">"Enter two numbers: "</span>);

        <span class="hljs-comment">// nextDouble() reads the next double from the keyboard</span>
        <span class="hljs-keyword">double</span> first = reader.nextDouble();
        <span class="hljs-keyword">double</span> second = reader.nextDouble();

        System.out.print(<span class="hljs-string">"Enter an operator (+, -, *, /): "</span>);
        <span class="hljs-keyword">char</span> operator = reader.next().charAt(<span class="hljs-number">0</span>);

        <span class="hljs-keyword">double</span> result;

        <span class="hljs-keyword">switch</span>(operator)
        {
            <span class="hljs-keyword">case</span> <span class="hljs-string">'+'</span>:
                result = first + second;
                <span class="hljs-keyword">break</span>;

            <span class="hljs-keyword">case</span> <span class="hljs-string">'-'</span>:
                result = first - second;
                <span class="hljs-keyword">break</span>;

            <span class="hljs-keyword">case</span> <span class="hljs-string">'*'</span>:
                result = first * second;
                <span class="hljs-keyword">break</span>;

            <span class="hljs-keyword">case</span> <span class="hljs-string">'/'</span>:
                result = first / second;
                <span class="hljs-keyword">break</span>;

            <span class="hljs-comment">// operator doesn't match any case constant (+, -, *, /)</span>
            <span class="hljs-keyword">default</span>:
                System.out.printf(<span class="hljs-string">"Error! operator is not correct"</span>);
                <span class="hljs-keyword">return</span>;
        }

        System.out.printf(<span class="hljs-string">"%.1f %c %.1f = %.1f"</span>, first, operator, second, result);
    }
}</code></pre>
<p><strong>Step 2) </strong>Output</p>
<pre><samp>Enter two numbers: 2.0
3.5
Enter an operator (+, -, *, /): *
2.0 / 3.5 = 7.0</samp></pre>
<p>The operator * entered by the user is stored in the operator variable using the Scanner object&#8217;s next) (method.</p>
<p>Similarly, using the nextDouble) (method of Scanner object, the two operands, 2.0 and 3.5 are stored in variables first and second respectively.</p>
<p><strong>Step 3) </strong>Since the operator / fits the condition &#8216;/&#8217; when:, the programme control jumps to</p>
<pre>result = first / second;</pre>
<p>This statement defines the product and stores the result of the variable and the break; the declaration ends the statement of the turn.</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-create-basic-calculator-program-with-java/">How to Create Basic Calculator Program with Java</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/how-to-create-basic-calculator-program-with-java/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
