Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me out with the simple calculator code Please!!!!

 
Deepakk Verma
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stuck with this code of simple calculator . this add's ,subtracts,multiplies,and divides given two numbers as the user enter's the wrong option (i.e., not mention in the menu) the program should ask for reentering the option.I cant find out how to do this.I have started learning java from past 3 days only

Also having problem in the line 25,29,33,37 about the " = " mentioned

PLEASE HELP

HERE IS THE CODE
===============================================================
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak.java .programmer wrote:


Please check your private messages for an important administrative matter
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And please http://faq.javaranch.com/java/UseCodeTags
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would find it easier if you used the % tags as in "formatting output" in this Java™ Tutorials section.
I would suggest you can simplify your code:
  • You only need one Scanner object.
  • Produce an operator String. You can have operator = "+"; or similar in your switch-case.
  • Then you only need one line which prints the result, after the end of the switch. You will get peculiar output if anybody enters 5, however!
  • Without changing anything like that, your problem is that you have results to be printed out which start with a number, and you want a String. To make them into Strings, try starting with the empty String "" and put that with a + at the beginning of each of your lines to print the result.
    You are also short of a + sign in each of those print statements; it shows the hazards of copy-and-paste; you have copied the error into all the statements.

    If you have only been doing Java for 3 days, it is hardly surprising you haven't worked out how to write a loop yet.
     
    Deepakk Verma
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you sir for your valuable suggestions. Your tips made me run this program smoothly and off course, i would definitely be working hard to learn all the concepts of java including loops as you find it surprising for a 3 day old student of not knowing about loops.
    That means there is something wrong with my studying approach .Thank you again for helping.
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 48972
    60
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    What I actually said was that I did not expect anybody to be familiar with loops after 3 days.


    Of course, you have a whole week's experience now . . .

    And "You're welcome "
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic