I have a program that prints the instance variables of objects stored in an arraylist. I want to add a feature to this program so it only prints the instance variables for first 10 objects, then ask the user to press enter to continue, then continues with the next 10 objects and so on.
Here is an example of how the printing loop looks without the function i'm asking for:
for (int i = 0; i < myList.size(); i++)
{
System.out.println(myList.get(i).getName();
}
The "Press enter to continue" part is easy enough:
import java.util.*;
...
Scanner input = new Scanner(System.in);
input.nextLine()
but how do i create a conditional loop that stops after 10 prints and then resumes after the "Press enter to continue" event??
for (int i = 0; i < myList.size(); i++)
{
System.out.println(myList.get(i).getName();
if(i % 10 == 0){
input.nextLine()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With