Exiting a program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hhhhhhhh
    New Member
    • Oct 2007
    • 12

    Exiting a program

    Hello all experts,

    How to exit a program without using ||,
    or without using break;
    or without using System.exit();

    Please help.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by hhhhhhhh
    Hello all experts,

    How to exit a program without using ||,
    or without using break;
    or without using System.exit();

    Please help.
    In Java you can't exit a program using the || operator nor using a break statement.
    When the main thread terminates and no other threads exist or just deamon threads
    exist the virtual machine will exit. Otherwise you have to use System.exit() but you
    don't want to use that.

    kind regards,

    Jos

    Comment

    • hhhhhhhh
      New Member
      • Oct 2007
      • 12

      #3
      Originally posted by JosAH
      In Java you can't exit a program using the || operator nor using a break statement.
      When the main thread terminates and no other threads exist or just deamon threads
      exist the virtual machine will exit. Otherwise you have to use System.exit() but you
      don't want to use that.

      kind regards,

      Jos
      Thanks for replying. This is regard to the ATM program. Suppose you have $1000 in your account. If you withdraw $900, the program will exit leaving you $100 balance. I am OK with this part.
      If you enter $1200, you will be asked to re-enter the correct amount. Otherwise, you will be asked to enter 0 or -1 to exit. How do you code this line? This is what I could not get.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by hhhhhhhh
        Thanks for replying. This is regard to the ATM program. Suppose you have $1000 in your account. If you withdraw $900, the program will exit leaving you $100 balance. I am OK with this part.
        If you enter $1200, you will be asked to re-enter the correct amount. Otherwise, you will be asked to enter 0 or -1 to exit. How do you code this line? This is what I could not get.
        You have to write that down in pseudo code using the words 'while' and/or 'do'
        and/or 'and', 'or'. If you can manage that and have test cased it for a couple of
        amounts, translating that pseudo code to Java will be a breeze. Just imagine
        you're the teller and someone wants to withdraw a negative amount of money,
        no money at all, a possible positive amount of money (<= account) or just too
        much money. What would you do?

        kind regards,

        Jos

        Comment

        Working...