Results 1 to 7 of 7
  1. #1
    khh717 is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Reading random order

    Please help. I need to write a program that reads name, address and salary in random order from the keyboard. I am suppose to use exception handling techniques. I was going to read the entire line as a string, then search for "," as a delimiter. If I do this, I do not believe I need exception handling. This must not be the best way to do this. How would you do it?

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Sorry, but that makes no sense to me at all. The keyboard is by definition a sequential input stream. How can you read it in random order?

    -Gary-

  3. #3
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    I think he means the input can come in as name, address, salary; or salary,name,address etc.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  4. #4
    khh717 is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    m00nchile is correct. The variables can be entered in random order. Any ideas how to do this?

  5. #5
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Finding the salary wouldn't be a problem, as you can try parsing it as a Integer, when you don't get an exception, that's your value. Differentiating between the name and adress could be a bit trickier, as they are both Strings, maybe go through both string and see which one has only letters (name), and which one has digits in it as well (adress).
    Ever seen a dog chase its tail? Now that's an infinite loop.

  6. #6
    khh717 is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    Thanks. That what I did. I did not know if there was a better way.

  7. #7
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Cool, as long as it gets the job done.
    Ever seen a dog chase its tail? Now that's an infinite loop.

Similar Threads

  1. Math.random in array and reverse order
    By eugenechia in forum New To Java
    Replies: 4
    Last Post: 02-17-2010, 04:33 AM
  2. Replies: 14
    Last Post: 10-19-2009, 11:57 AM
  3. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  4. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  5. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM

Tags for this Thread

Posting Permissions

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