Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 29 of 29

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

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,929
    Thanks
    59
    Thanked 2,697 Times in 2,647 Posts

    Default 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:
    startIndex = Integer.valueOf(inputReader.nextInt());
    It reads an int, creates an Integer to hold that int and then extras that int to assign it to a variable.
    Why not just assign the int to the variable"
    startIndex = inputReader.nextInt();
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Sep 2022
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Quote Originally Posted by Norm View Post
    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 then extras that int to assign it to a variable.
    Why not just assign the int to the variable"
    What do you mean by the code does not check the user's input for validity?

    You have a point about assigning an int to a variable only, I am used to that. I try to understand my coding more often because I sometimes just copy things and forget their meaning.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    24,929
    Thanks
    59
    Thanked 2,697 Times in 2,647 Posts

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

    code does not check the user's input for validity?
    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 should prompt the user for the values to load into the array with comment about ending the input with -1
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    Sep 2022
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    Quote Originally Posted by Norm View Post
    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 should prompt the user for the values to load into the array with comment about ending the input with -1
    I can think of those scenarios in my project. However, the exercise was limited to what it requested from me. I think this is the final solution to the exercise. However, time is against me to work on one project. I have been given around 120 projects for a short period of time.

    More questions will be asked and I hope I won't be a burden to you

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: May 16th, 2012, 05:15 PM
  2. user input going to wrong ArrayList
    By havinFun in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 15th, 2012, 02:58 PM
  3. [SOLVED] Returning ArrayList via user input
    By IanSawyer in forum Collections and Generics
    Replies: 4
    Last Post: March 27th, 2012, 05:40 PM
  4. Need help with user input/output for GUI.
    By Tctwins in forum AWT / Java Swing
    Replies: 6
    Last Post: February 20th, 2012, 04:13 PM
  5. JTable Updating String Values from User Input
    By aussiemcgr in forum AWT / Java Swing
    Replies: 5
    Last Post: August 3rd, 2010, 01:48 PM

Tags for this Thread