aspose file tools*
The moose likes Beginning Java and the fly likes Help me out with the simple calculator code Please!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help me out with the simple calculator code Please!!!!" Watch "Help me out with the simple calculator code Please!!!!" New topic
Author

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

Deepakk Verma
Ranch Hand

Joined: Sep 09, 2009
Posts: 31
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

Joined: Jul 26, 2007
Posts: 9990
    
    7

Deepak.java .programmer wrote:


Please check your private messages for an important administrative matter


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

And please http://faq.javaranch.com/java/UseCodeTags


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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

    Joined: Sep 09, 2009
    Posts: 31
    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

    Joined: Oct 13, 2005
    Posts: 36508
        
      16
    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 "
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Help me out with the simple calculator code Please!!!!
     
    Similar Threads
    While and Do-While Question
    Having trouble with switch, case,break,
    Battleships - guys please help me out!
    Do while error, I'm going crazy
    Help with english to morse code program, I have no idea what I'm doing