command line arguments in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #16
    Originally posted by mira88
    Oh I guess thats wrong then.
    Of course you could start by checking for args.length == 0 and outputing an "error" message straight away.

    B.T.W Welcome to the wonderful world of error/exception handling.

    Comment

    • blazedaces
      Contributor
      • May 2007
      • 284

      #17
      Originally posted by r035198x
      Of course you could start by checking for args.length == 0 and outputing an "error" message straight away.

      B.T.W Welcome to the wonderful world of error/exception handling.
      She could also check if args.length == 0 and if so, ask the user if he would like to input a set of numbers now, then ask for how many, and ask for each number one at a time to be inputted...

      -blazed <-- like to avoid error/exception handling, even though it's impossible

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #18
        Originally posted by blazedaces
        She could also check if args.length == 0 and if so, ask the user if he would like to input a set of numbers now, then ask for how many, and ask for each number one at a time to be inputted...

        -blazed <-- like to avoid error/exception handling, even though it's impossible
        Sure, if I were the user then I'd confirm and then state that I would like to enter
        -42 numbers; then just wait ... ;-)

        kind regards,

        Jos

        Comment

        • blazedaces
          Contributor
          • May 2007
          • 284

          #19
          Originally posted by JosAH
          Sure, if I were the user then I'd confirm and then state that I would like to enter
          -42 numbers; then just wait ... ;-)

          kind regards,

          Jos
          Like I said, it's impossible to avoid, but realizing this, simply add a if input is negative with a while loop that simply asks again for an input till it's positive (still trying to avoid spitting out the error, even though it's the same thing)...

          bleh!

          -blazed

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Originally posted by blazedaces
            Like I said, it's impossible to avoid, but realizing this, simply add a if input is negative with a while loop ....
            and also if input is a number and if input is a valid number ....?

            Comment

            • blazedaces
              Contributor
              • May 2007
              • 284

              #21
              Originally posted by r035198x
              and also if input is a number and if input is a valid number ....?
              Doesn't scanner class automatically check if you're asking for a nextInt() or nextDouble() or any number...?

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #22
                Originally posted by blazedaces
                Doesn't scanner class automatically check if you're asking for a nextInt() or nextDouble() or any number...?
                Now you're talking. And what does it do if the input doesn't match?

                Comment

                • blazedaces
                  Contributor
                  • May 2007
                  • 284

                  #23
                  Originally posted by r035198x
                  Now you're talking. And what does it do if the input doesn't match?
                  Throw an error/exception, prints the stack automatically.. . are you still agreeing with me that despite my hatred for them it's impossible to avoid error/exception handling? I know, I know...

                  All in good fun ;)

                  -blazed

                  Comment

                  Working...