Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Simple Calculator
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="ArchoCrime" data-source="post: 298535" data-attributes="member: 51291"><p>Hello,</p><p></p><p>I'm new to Java and I just wanted to release this useless script I've had in my files for a bit now.</p><p>If you know how to work with java, then make it openable, I don't feel like making a tutorial on it.</p><p></p><p>[CODE]import java.util.Scanner;</p><p></p><p>public class Calculator {</p><p></p><p>public static void main(String[] args) {</p><p></p><p> Scanner input = new Scanner(System.in);</p><p></p><p> Maths Maths = new Maths();</p><p></p><p> double answer = 0;</p><p> double inputA, inputB;</p><p> char operator;</p><p> boolean done = false;</p><p></p><p> while (done == false) {</p><p> System.out.print("Please enter your sum: ");</p><p></p><p> inputA = input.nextDouble();</p><p> operator = input.next().charAt(0);</p><p> inputB = input.nextDouble(); </p><p></p><p> switch (operator) {</p><p> case '+': answer = Maths.add(inputA, inputB);</p><p> break;</p><p> case '-': answer = Maths.subtract(inputA, inputB);</p><p> break;</p><p> case '*': answer = Maths.multiply(inputA, inputB);</p><p> break;</p><p> case '/': answer = Maths.divide(inputA, inputB);</p><p> break;</p><p> case '^': answer = Maths.power(inputA, inputB);</p><p> break;</p><p> }</p><p></p><p> System.out.println(answer); </p><p> } </p><p></p><p> input.close();</p><p></p><p> }</p><p></p><p>}</p><p></p><p>public class Maths {</p><p></p><p> double add(double a, double b) {</p><p> double answer = a+b;</p><p> return answer; </p><p> }</p><p></p><p> double subtract(double a, double b) {</p><p> double answer = a-b;</p><p> return answer; </p><p> }</p><p></p><p> double multiply(double a, double b) {</p><p> double answer = a*b;</p><p> return answer; </p><p> }</p><p></p><p> double divide(double a, double b) {</p><p> double answer = a/b;</p><p> return answer; </p><p> }</p><p></p><p> double power(double a, double b){</p><p> double answer =a;</p><p></p><p> for (int x=2; x<=b; x++){</p><p> answer *= a;</p><p> }</p><p></p><p> return answer;</p><p> }</p><p></p><p>}[/CODE]</p><p></p><p>I know, I'm a noob. Don't go to be hating, I'm new to Java <img src="/styles/default/xenforo/smilies/emojione/smile.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></p></blockquote><p></p>
[QUOTE="ArchoCrime, post: 298535, member: 51291"] Hello, I'm new to Java and I just wanted to release this useless script I've had in my files for a bit now. If you know how to work with java, then make it openable, I don't feel like making a tutorial on it. [CODE]import java.util.Scanner; public class Calculator { public static void main(String[] args) { Scanner input = new Scanner(System.in); Maths Maths = new Maths(); double answer = 0; double inputA, inputB; char operator; boolean done = false; while (done == false) { System.out.print("Please enter your sum: "); inputA = input.nextDouble(); operator = input.next().charAt(0); inputB = input.nextDouble(); switch (operator) { case '+': answer = Maths.add(inputA, inputB); break; case '-': answer = Maths.subtract(inputA, inputB); break; case '*': answer = Maths.multiply(inputA, inputB); break; case '/': answer = Maths.divide(inputA, inputB); break; case '^': answer = Maths.power(inputA, inputB); break; } System.out.println(answer); } input.close(); } } public class Maths { double add(double a, double b) { double answer = a+b; return answer; } double subtract(double a, double b) { double answer = a-b; return answer; } double multiply(double a, double b) { double answer = a*b; return answer; } double divide(double a, double b) { double answer = a/b; return answer; } double power(double a, double b){ double answer =a; for (int x=2; x<=b; x++){ answer *= a; } return answer; } }[/CODE] I know, I'm a noob. Don't go to be hating, I'm new to Java :) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Simple Calculator
Top