So my issue is that I would like to add elements into an ArrayList using the Scanner kb. I also want to make sure that the input (number) is between 0 and 100 inclusive. The code I have does not run as I want. How can I resolve this ? Thanks.
public static void addNum(final ArrayList<Double> myAList, final Scanner kb)
{
//Prompt user for a number 0-100
if(!(kb == null || myAList == null))
{
System.out.println("Please enter a number between (0 - 100): ");
double number = kb.nextDouble();
kb.nextLine();
while(number < 0 || number > 100)
{
System.out.println("That was not a qualified number, try again");
number = kb.nextDouble();
kb.nextLine();
}
for(int x = 0; x < myAList.size() - 1; x++);
{
myAList.add(number);
}
}
myAList.trimToSize();
}
myAListcome from? It could already have had those numbers added in.nextDouble. You want this to be a minimal reproducible example, with the current missing piece being "complete".System.out.println()statements to your code or use a debugger from an IDE. If you still need help, please post a complete example that we can compile and run ourselves. Also show a sample run to show what input you use and the output you get.