• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
===============================================================
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak.java .programmer wrote:



Please check your private messages for an important administrative matter
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please http://faq.javaranch.com/java/UseCodeTags
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Marshal
    Posts: 76862
    366
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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 "
     
    Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic