Write a program that will prompt the user to enter a number, n, of men. Fill a L
ID: 652017 • Letter: W
Question
Write a program that will prompt the user to enter a number, n, of men. Fill a LinkedList with n Integer objects numbered 1,2,...,n. The Collections class has an algorithm called rotate(List list, int distance) which can be used to rotate a list left or right. Write the logic necessary to eliminate every other Integer beginning with the Integer in the second position. Remember that if you remove an item in the middle of the list, the items which follow it are shifted forward in the list. Continue eliminating integers until a single Integer is left. Print the list for each step in this process and the survivor's position. As an example of this process, if we represent five men with a list of integers. [ 1,2.3.4.5], rotate the list to the left and remove the first man each time, we would see lists like this:Explanation / Answer
import java.util.Scanner; public class test2 { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Enter a string"); String s = input.nextLine; String lower = ""; String total = ""; for (int i = 0; i = 87 && thisCharRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.