5.
Modify the program for Line Numbers from L09: In-ClassAssignment. Mainly, you are changing the
problem from using arrays to ArrayLists. There are some othermodifications as well, so read the instructions carefully.
The program should do the following:
–Ask the user for how many lines of text they wish to enter
–Declare and initialize an **ArrayList** of Strings to hold theuser’s input
–Use a do-while loop to prompt for and read the Strings (linesof text) from the user
at the command line until they enter a sentinel value
–After the Strings have been read, use a for loop to stepthrough the ArrayList of
Strings and concatenate a number to the beginning of each lineeg:
This is change to 1 This is
The first day change to 2 The first day
and so on…
–Finally, use a **for each** loop to output the Strings(numbered lines) to the command
line.
*/
Below is L09 in-class assignment for part 5
2. Create a new program. This is the program you will submit forpoints today.
Write a Java code snippet to do the following:
– Declare and allocate an ArrayList of Strings
– Use a do-while loop to prompt for and read the Strings (lines oftext)
from the user at the command line until they enter a sentinelvalue.
- Use a for loop to step through the ArrayList and concatenate aline number
to the beginning of each line eg:
This is change to 1 This is
The first day change to 2 The first day
and so on…
– Finally, use a for loop to output the Strings (numbered lines)to the command line.
*/
Scanner scnr = new Scanner(System.in);
System.out.println(\"How many lines of text do you want toenter?\");
 Â
int numLines = 0;
numLines = scnr.nextInt();
System.out.println();
 Â
String [] arrayLines = new String[numLines];
scnr.nextLine();
 Â
int i = 0;
while(i < numLines)
{
System.out.println(\"Enter your text: \");
String text = scnr.nextLine();
arrayLines[i] = text;
i++;
}
 Â
for(i = 0; i < numLines; i++)
{
arrayLines[i] = (i + 1) + \" \" + arrayLines[i];
}
 Â
for(String element: arrayLines)
{
System.out.println(element);
}
}
 Â
}