想請問JAVA如何做簡易計算機

想請問用java寫出 加減乘除 四則運算

要有 先乘除後加減 的功能~~~~~

例如

輸入 1-5+7=

按enter 輸出 3

輸入 1+7*2+1=

按enter 輸出 16

輸入 不合法的數值

都輸出為0

請問哪裡有完整程式或 教學

1 Answer

Rating
  • Chen
    Lv 6
    8 years ago
    Favorite Answer

    2 method:

    1. build binary tree and parse with postfix ( the method need stack for operand ). the method is stupid, but general people adopts it.

    2. adopt LL / LR method: You work as coding compiler.

    statement -> expression

    expression -> simple_expression relation_operand simple_expression

    | simple_expression

    simple_expression -> terminal + terminal

    | terminal - terminal

    | terminal

    terminal -> factor * factor

    | factor / factor

    | factor

    factor-> ID

    | number

    | float

    | ( expression ) ===> recursive descent

    I suggest You should adopt second method.

    I have experienced in coding OS of supercomputer(VAX, CDC CYBER) since I was 10 years old, Now I am good at database design( B*tree, Rtree, transaction process, parse SQL ) like ORACLE, compiler and linker design, virtual reality( 3D)and image processing, machining learing, data mining, face recognition, hand writting recognition, biometrics and bioinformatics ...etc. above mentioned knowledges learns process by myself.

Still have questions? Get your answers by asking now.