Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

[TUT]Your First Calculator in Four Easy Steps[TUT]

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'.
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.
Thanks Mate =). This was helpful. Good Share.
thanks all you positive commenters. and thanks postmortis for you zero devision source code.
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...
(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?
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!
How is this an advanced calculator?
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
(Nov 13, 2010 08:20 PM)BeezyB Wrote:  How is this an advanced calculator?

read the entire post and you'll see that your post was redundant
(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 👍
(Nov 14, 2010 07:17 AM)BeezyB 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.
(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"?
fucking [censored].. meeehhhh -_--
Sorry bout the pics. I don't even have the pics anymore.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by ScrewbaccaDec 2, 2016 10:50 AM 19 1,366 Dec 2, 2016 10:50 AM
Last Post: Goodies
[C] by NielyMar 22, 2014 08:21 AM 8 210 Mar 22, 2014 08:21 AM
Last Post: Niely
[.NET] by KeeloFeb 9, 2013 10:39 PM 5 401 Feb 9, 2013 10:39 PM
Last Post: 0xDEAD10CC