Search:

Type: Posts; User: Norm

Search: Search took 0.21 seconds.

  1. Re: [SOLVED] How to output a range of values from arraylist and user input

    What if user enters From/To as -1 9999
    or 4 1
    Should the program detect those invalid inputs and give an error message? Or just let the code throw an exception?

    Another point - the program...
  2. Re: [SOLVED] How to output a range of values from arraylist and user input

    Some comments:
    The code does not check the user's input for validity. EG in range and in order

    This statement does a lot of extra work:

    It reads an int, creates an Integer to hold that int and...
  3. Re: How to output a range of values from arraylist and user input

    Glad you got it working.

    A working solution might be helpful for others.
  4. Re: How to output a range of values from arraylist and user input

    That is not true. A program can ask many questions without declaring any variables.
    A variable must be declared before it is used.
    Asking a question and using a variable do not need to be...
  5. Re: How to output a range of values from arraylist and user input

    Did you try it?
    The code would like like this:
    print the message
    read user's response to the message

    If you print the value that was read, it will appear on the console 2 times ( that is the...
  6. Re: How to output a range of values from arraylist and user input

    When you type in the input 0 and 3, they are displayed on the console where and when they are typed.
    To have them appear after the messages: From where? and To where?
    you need to print the...
  7. Re: How to output a range of values from arraylist and user input

    I don't see where the problem is. The console output looks as expected.

    What do you think the output should look like? Can you post what you expect to see?
  8. Re: How to output a range of values from arraylist and user input

    Please copy the console's contents and paste it here. No images. Text can not be copied from an image to include in a response.


    Please post the new code and the contents of the console from...
  9. Re: How to output a range of values from arraylist and user input

    The code reads the 0 before it prints out the From where message.
    The code to read the 0 is outside of the loop. Add a print statement after the loop that prints out the contents of the array....
  10. Re: How to output a range of values from arraylist and user input

    It does for me. Can you run the program, copy the output window and paste it here so I can see?
  11. Re: How to output a range of values from arraylist and user input

    It returns -1 if this list does not contain the element.
    How else can it say the value was not found?


    inclusive means it includes that value
    exclusive means it does not include that value...
  12. Re: How to output a range of values from arraylist and user input

    Read the API doc for the indexOf method. It clearly says that a -1 can be returned.

    Add some print statements that print out the values of all the variables the code uses so that you can see what...
  13. Re: How to output a range of values from arraylist and user input

    That says the error was at line 27 where the code calls the subList method.

    You can see the contents of the list by printing it after the end of the loop that gets its contents.

    Look at the API...
  14. Re: How to output a range of values from arraylist and user input

    What line did that error happen on? How did the value of -1 come to be used as an index?
    The message says an invalid index of -1 was used on that line. The valid indexes range from 0 to the length...
Results 1 to 14 of 14