I have attached 2 java files which, when run, simulate a calculator that performs addition and multiplication only. I have been working on it for some time...getting assistance from varioius sources. I am having two issues I need help in correcting. They are as follows:

1) When multiplying two single digit numbers...a leading zero is attached
to the bottom digit (num2) I wish to remedy this by either removing it
for single digits or add a zero to the top digit (num1). I'm referring
to the output display.

2) When the output is displayed...the top number (num1) is shifted to
much to the right. I would like for it to be a bit more uniform.


I am trying to learn JAVA and this is my first attempt at a program other than the example from "JAVA for Dummies!" lol. Thanks in advance.

You'll have to explain the 1st question a little more.

One the second question, if you are using a JTextField to display data, you can set the horizontal alignment.

textField.setHorizontalAlignment(JTextField.CENTER);
                                                    or   .RIGHT
                                                    or   .LEFT
                                                    or   .LEADING
                                                    or   .TRAILING

Can you enhance your program with adding and subtracting method as well? I'd love to see the complete calculator if you dont mind. The program occurs because of your display method. You'll need to add some code to check if the preceeding number is 0, it has to be gotten rid of before being printed out to the screen.

To server_crash, you will understand the first question if you try to run the program with some trial input. About the second question, I dont think your answer is helpful at all.

To server_crash, you will understand the first question if you try to run the program with some trial input. About the second question, I dont think your answer is helpful at all.

I don't have time to run everyone's code. If you do, that's great. About your second comment, I just now looked at the code and saw that he's using the command line to run this.d

hi compiler

I have changed your code at a couple of places.
try running your code and tell me is this what was in your mind?

regards
Srinivas

You succeed in get rid of the leading Zero in the output. That's great. But what I am trying to do is come up with a better algorithm for the muliplication method. When I entered a 10 digit number times another 8 digit number, it would take like forever to get the answer. There's a huge Big O for the efficiency of this program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.