Answer:
follows are the program code to this question:
import java.security.SecureRandom;//import package SecureRandom
import java.util.*;//import uitl package for use input
class Main//defining class Main
{
public static void main(String[] args) //defining main method
{
int max = 25;//Defining an integer variable max
SecureRandom r = new SecureRandom();//creating SecureRandom class object
LinkedList<Integer> n= new LinkedList<Integer>();//Defining LinkedList class object
for(int i = 0; i <max; i++)//Defining for loop input value
{
int x = r.nextInt(100);//Defining integer variable x that use random function for hold value
n.add(x);//use LinkedList that use add method to add value in list
}
System.out.println("The original order of list: ");//print message
ListIterator it = n.listIterator();//create ListIterator object that hold LinkedList value
while(it.hasNext())//use while loop for check value
{
System.out.println(it.next());//use print method that prints ListIterator value
}
System.out.println("The reverse order of list: ");//print message
ListIterator itrev = n.listIterator(n.size());//create ListIterator object that hold LinkedList size value
while(itrev.hasPrevious())//Defining loop for print value in reverse order
{
System.out.println(itrev.previous());//print value
}
}
}
output:
please find the attached file.
Step-by-step explanation:
In the above-given program inside the main method, an integer variable "max" is defined that holds an integer value, and in the next step, "SecureRandom and LinkedList" object is created, which is uses the for loop for in the loop it uses the "rand and add" method to assign value in the List.
In the next step, the "ListIterator" object has been created, that use while loop for creating the "ListIterator" object to hold size value and use the while loop to print the value in the reverse order and print its value.