#how to find the sum of two specific arraylist integers?
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
the goal is to find the sum of the second and third number inputted
what are the indices of the second and third numbers?
the break keyword is not the right choice in this code since it exits the while loop. U could use another keyword in its place or restructure the logic.
the break is here to exit an infinite loop
but its used wrong
used wrong how?
because it doesnt add 0s to the list
0 is used as a sentinel value, it doesn't need to be added to a list
also, adding 0 does nothing
don't ever use System.exit() if that's what you mean
no i mean if scanner.nextLine() returns "exit"
then u have to make ur reading a two stage process
scanner.nextLine() and put that into a string variable
now check if it's exit with a simple if
if it is, break ur loop and whatever
if its not, Integer.parseInt(...) the string variable and continue with ur current logic
@fleet quartz , just in case you're confused. You want to answer Quintegar's question that I've replied to and ignore the rest of this conversation.
oh gosh, didn't even notice. sorry for the confusion