Hack Forums
[Java] [TUT]Your First Calculator in Four Easy Steps[TUT] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] [TUT]Your First Calculator in Four Easy Steps[TUT] (/showthread.php?tid=282939)

Pages: Pages 1 2 3 4 5


* - Postmortis - Feb 23, 2010

Good basic calculator,


Slightly modified to so it gives you an error when you divide by zero unless you divide 0 by 0 itself if your interested...

Spoiler (Click to View)



I am not flaming, just posting this if you wanted to find out how to fix this 'problem'.


* - Batchβ„’ - Feb 23, 2010

I like it..I mean im not into Java im into Python but still this is a good and easy tutorial even I could understand.


* - TheBlackMarket - Feb 23, 2010

Thanks Mate =). This was helpful. Good Share.


* - eXero - Feb 23, 2010

thanks all you positive commenters. and thanks postmortis for you zero devision source code.


* - pro-phecy - Nov 13, 2010

I know i'm bringing this thread back from the grave, but I am a just starting java as of Wednesday and I was wondering if it was possible to put a space between the numbers. I put a space around the " = " so the result and second number would be space out, but my problem was figuring out a way to put a space around the operator. Since operator could be 1 of 4 commands, how would you right the if statement for each command to put a space around the operator. If you know what I'm trying to describe...


* - Ben121 - Nov 13, 2010

(Nov 13, 2010 09:44 AM)pro-phecy Wrote:  I know i'm bringing this thread back from the grave, but I am a just starting java as of Wednesday and I was wondering if it was possible to put a space between the numbers. I put a space around the " = " so the result and second number would be space out, but my problem was figuring out a way to put a space around the operator. Since operator could be 1 of 4 commands, how would you right the if statement for each command to put a space around the operator. If you know what I'm trying to describe...

At least your post isn't a retarded one like most grave digging posts.
Try something like this:
Code
System.out.println(num1 + " " + operator + " " + num2 + " = " + result);
Is that what you mean?


* - pro-phecy - Nov 13, 2010

yeah, that's exactly what I meant! I tried to put the space between the + signs like
Code
System.out.println(num1 " " + operator " " + num2 + " = " + result);

when using a space in a calculation, do you always put (+) around a space? so it prints it or how does that work?

and thanks once again Ben!


* - BeezyB - Nov 13, 2010

How is this an advanced calculator?


* - MrZander - Nov 13, 2010

Ehh it's not what I would call "advanced"

Maybe if it did like log and trig functions, or at the very least square roots and exponents


* - pro-phecy - Nov 14, 2010

(Nov 13, 2010 08:20 PM)JBow94 Wrote:  How is this an advanced calculator?

read the entire post and you'll see that your post was redundant


* - BeezyB - Nov 14, 2010

(Nov 14, 2010 12:28 AM)pro-phecy Wrote:  read the entire post and you'll see that your post was redundant

Nah bro πŸ˜…

It's a public forum for public opinions, if that's how I feel, I can most certainly express it πŸ‘


* - pro-phecy - Nov 14, 2010

(Nov 14, 2010 07:17 AM)JBow94 Wrote:  Nah bro πŸ˜…

It's a public forum for public opinions, if that's how I feel, I can most certainly express it πŸ‘

I'm not saying you can't express it, but your question and answer has already been posed and answered, which makes it "seem" redundant.


* - BeezyB - Nov 14, 2010

(Nov 13, 2010 09:44 AM)pro-phecy Wrote:  I know i'm bringing this thread back from the grave, but I am a just starting java as of Wednesday and I was wondering if it was possible to put a space between the numbers. I put a space around the " = " so the result and second number would be space out, but my problem was figuring out a way to put a space around the operator. Since operator could be 1 of 4 commands, how would you right the if statement for each command to put a space around the operator. If you know what I'm trying to describe...

I'm not 100% sure what you're asking but maybe this little snippet of code will help:

Code
System.out.println(String.format("1 + 2 = %1$d", 1 + 2));

Try that, is that what you meant by "space around the operator"?


* - Vuz - Nov 14, 2010

fucking [censored].. meeehhhh -_--


* - eXero - Nov 14, 2010

Sorry bout the pics. I don't even have the pics anymore.