Im currently working on a project that lets you add, subtract, multipy, or divide 2 integers, and then gives you the answer
I wanted to put a while or do-while switch on it so that when you get your answer,
it restarts itself and prompts you to pick which operand you want and which two integers to be used, but I havent been
able to figure it out.
Help and suggestions would be great! Please explain your logic behind your reasoning!
What did you try and what specific problem are you having? I don't see a while or do/while in that code. Have you gone through a tutorial or textbook section on while and do/while loops? If not, that's your starting point. Then take your best shot, and then post a more specific question if you get stuck.
Some poor code style there.
You have far too long a main method. The ideal length for a main method is one statement. You have a lot of repeated code, which ought to be refactored into separate methods. Some of it should be refactored into a utility class (that example has different methods from what you want).
To augment on Campbell's response: repetitious code is a typical beginner's mistake. We all did it when we were starting out, so it's no badge of shame -- just something to start learning to recognize and correct. See that the code in each case of the switch block is almost identical. The only difference is the operation that is performed to determine what value is assigned to answer (and the corresponding symbol that is printed out). Try to spot repetitions like this in your code, and see if there is a way that all the common code could be consolidated. If you change your perspective on this problem somewhat, you may find that you don't need the switch block at all.
Well I got to theory crafting and started trying random stuff, I put the whole code, give or take a few brackets, in a do - while loop, and made sure the "Int choice = 0;" was outside the loop, final code looks like this...
I remember you saying
1. that you doubted the design of a do - while switch that exits from inside itself
2. that my main method was way too long, and alot of repeated code.
Do you think you could elaborate for future reference? Would be very helpful