Results 1 to 3 of 3
  1. #1
    kokoko is offline Member
    Join Date
    Sep 2009
    Posts
    1
    Rep Power
    0

    Default How do I make a string math action into a real one?

    I have this program that gets 2 numbers and an action ("+/*^-")..
    I was wondering if there's a way to make that string into an action or do I have to make if's (or switch-case)?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    If this is a school assignment then an if-else or switch should do it.
    Realize though that the switch would need a char not an int.

    Otherwise you can have a look at the JavaScript engine shipped with Java 6.

  3. #3
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    You may want to push and pop operands off a stack if you want to have order of operations ie
    Java Code:
    2 + 3 * 6 != ( 2 + 3 ) * 6

Similar Threads

  1. make a string as a link
    By pharo in forum AWT / Swing
    Replies: 1
    Last Post: 04-26-2009, 12:23 PM
  2. Have a period in string, how to make it look nicer
    By JordashTalon in forum New To Java
    Replies: 6
    Last Post: 03-06-2009, 12:23 AM
  3. simplest way to make 2d array to string
    By Tamu in forum Advanced Java
    Replies: 4
    Last Post: 11-25-2008, 04:50 PM
  4. how do i make a string return a number?
    By pjr5043 in forum New To Java
    Replies: 6
    Last Post: 09-15-2008, 04:56 AM
  5. make a variable name from a string?
    By Kinnikinnick in forum New To Java
    Replies: 3
    Last Post: 11-13-2007, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •