This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
After a relatively small C++ background, I decided to learn some Java. I want to be able to pass two variables from my main class, evaluate them in another class, and return that answer to the main class. I have all the code done for it pretty much, but I can't figure out how to use the returned variable in my main class. Any help would be appreciated!
I just tried adding a "System.out.println(answer)" in the case inside the switch statement, but I got an error saying that "answer cannot be resolved to a variable." I'm sure this is a quick fix, but I couldn't find anything helpful by googling it, so any help would be awesome.
You have fallen into a trap which lots of people fall into. You are writing too much code all in the same place. You are going to write enter 1st number enter 2nd number four times. That is not at all good style. That ought to be moved somewhere else. A separate method. Maybe even in a separate class. Create an Arithmetic class with two fields for the two numbers, and sum() difference() product() quotient() (=divide) and remainder() methods.