Is there a way to keep track of the elements and to loop the menu?How does the Java 'for each' loop work?What is the best way to iterate over a dictionary?What's the simplest way to print a Java array?Accessing the index in 'for' loops?How do I loop through or enumerate a JavaScript object?JavaScript closure inside loops – simple practical exampleHow do I break out of nested loops in Java?Looping through the content of a file in BashLoop through an array in JavaScriptWould it make any difference giving arguments using scanner class instead of command line arguments?

Why were movies shot on film shot at 24 frames per second?

Is refusing to concede in the face of an unstoppable Nexus combo punishable?

How to dismiss intrusive questions from a colleague with whom I don't work?

Are there any plans for handling people floating away during an EVA?

How to create a summation symbol with a vertical bar?

How to setup a teletype to a unix shell

Can a group have a cyclical derived series?

How to organize ideas to start writing a novel?

Can I submit a paper under an alias so as to avoid trouble in my country?

Why don't politicians push for fossil fuel reduction by pointing out their scarcity?

How do you call it when two celestial bodies come as close to each other as they will in their current orbits?

Do I have to learn /o/ or /ɔ/ separately?

Is there a known non-euclidean geometry where two concentric circles of different radii can intersect? (as in the novel "The Universe Between")

Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?

Does C++20 mandate source code being stored in files?

Is "es" necessary in this sentence?

Why would the US President need briefings on UFOs?

How to persuade recruiters to send me the Job Description?

Why doesn't the Falcon-9 first stage use three legs to land?

Ask for a paid taxi in order to arrive as early as possible for an interview within the city

Why does my house heat up, even when it's cool outside?

Why doesn't mathematics collapse even though humans quite often make mistakes in their proofs?

To "hit home" in German

How to "know" if I have a passion?



Is there a way to keep track of the elements and to loop the menu?


How does the Java 'for each' loop work?What is the best way to iterate over a dictionary?What's the simplest way to print a Java array?Accessing the index in 'for' loops?How do I loop through or enumerate a JavaScript object?JavaScript closure inside loops – simple practical exampleHow do I break out of nested loops in Java?Looping through the content of a file in BashLoop through an array in JavaScriptWould it make any difference giving arguments using scanner class instead of command line arguments?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















The program needs to be able to enter people into a Queue and keep track of them. the user has 3 options "A" to enter a new person(int) into the queue, "N" to just let the queue be processed, and "Q" to quit the queue and to then display how many people are in the queue. I can't quite figure out how to loop and keep track.



package pkg3650queue;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner; // Import the Scanner class

public class Main
/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
Queue<Integer> line = new LinkedList<Integer>();
Scanner input = new Scanner(System.in);
Scanner addperson = new Scanner(System.in);

String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
System.out.println("Enter a number to add a person to the line: ");
int addtoLine = addperson.nextInt();
line.add(addtoLine);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");
else if (option.equalsIgnoreCase("N"))
if(line.isEmpty())
System.out.println("There are no elements in the line to be processed");
System.exit(0);

else
int requestsProccessed = line.remove();
System.out.println(requestsProccessed);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");



while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());











share|improve this question


























  • Not related to your problem, but to simplify your code, instead of using option.equals("q") || option.equals("Q") you can do option.equalsIgnoreCase("q"). See the corresponding doc

    – vincrichaud
    Mar 27 at 15:34











  • You may just put all your code (from the displying of the question, to the end) inside a loop. Use a boolean flag as the condition of your loop. When the user enter q set the flag to false.

    – vincrichaud
    Mar 27 at 15:36

















0















The program needs to be able to enter people into a Queue and keep track of them. the user has 3 options "A" to enter a new person(int) into the queue, "N" to just let the queue be processed, and "Q" to quit the queue and to then display how many people are in the queue. I can't quite figure out how to loop and keep track.



package pkg3650queue;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner; // Import the Scanner class

public class Main
/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
Queue<Integer> line = new LinkedList<Integer>();
Scanner input = new Scanner(System.in);
Scanner addperson = new Scanner(System.in);

String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
System.out.println("Enter a number to add a person to the line: ");
int addtoLine = addperson.nextInt();
line.add(addtoLine);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");
else if (option.equalsIgnoreCase("N"))
if(line.isEmpty())
System.out.println("There are no elements in the line to be processed");
System.exit(0);

else
int requestsProccessed = line.remove();
System.out.println(requestsProccessed);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");



while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());











share|improve this question


























  • Not related to your problem, but to simplify your code, instead of using option.equals("q") || option.equals("Q") you can do option.equalsIgnoreCase("q"). See the corresponding doc

    – vincrichaud
    Mar 27 at 15:34











  • You may just put all your code (from the displying of the question, to the end) inside a loop. Use a boolean flag as the condition of your loop. When the user enter q set the flag to false.

    – vincrichaud
    Mar 27 at 15:36













0












0








0








The program needs to be able to enter people into a Queue and keep track of them. the user has 3 options "A" to enter a new person(int) into the queue, "N" to just let the queue be processed, and "Q" to quit the queue and to then display how many people are in the queue. I can't quite figure out how to loop and keep track.



package pkg3650queue;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner; // Import the Scanner class

public class Main
/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
Queue<Integer> line = new LinkedList<Integer>();
Scanner input = new Scanner(System.in);
Scanner addperson = new Scanner(System.in);

String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
System.out.println("Enter a number to add a person to the line: ");
int addtoLine = addperson.nextInt();
line.add(addtoLine);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");
else if (option.equalsIgnoreCase("N"))
if(line.isEmpty())
System.out.println("There are no elements in the line to be processed");
System.exit(0);

else
int requestsProccessed = line.remove();
System.out.println(requestsProccessed);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");



while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());











share|improve this question
















The program needs to be able to enter people into a Queue and keep track of them. the user has 3 options "A" to enter a new person(int) into the queue, "N" to just let the queue be processed, and "Q" to quit the queue and to then display how many people are in the queue. I can't quite figure out how to loop and keep track.



package pkg3650queue;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner; // Import the Scanner class

public class Main
/**
* @param args the command line arguments
*/
public static void main(String[] args)
// TODO code application logic here
Queue<Integer> line = new LinkedList<Integer>();
Scanner input = new Scanner(System.in);
Scanner addperson = new Scanner(System.in);

String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
System.out.println("Enter a number to add a person to the line: ");
int addtoLine = addperson.nextInt();
line.add(addtoLine);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");
else if (option.equalsIgnoreCase("N"))
if(line.isEmpty())
System.out.println("There are no elements in the line to be processed");
System.exit(0);

else
int requestsProccessed = line.remove();
System.out.println(requestsProccessed);
System.out.println(line);
System.out.println("There are " + line.size() + " people in the queue");



while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());








java loops queue






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 21:15







Osama

















asked Mar 27 at 15:26









OsamaOsama

83 bronze badges




83 bronze badges















  • Not related to your problem, but to simplify your code, instead of using option.equals("q") || option.equals("Q") you can do option.equalsIgnoreCase("q"). See the corresponding doc

    – vincrichaud
    Mar 27 at 15:34











  • You may just put all your code (from the displying of the question, to the end) inside a loop. Use a boolean flag as the condition of your loop. When the user enter q set the flag to false.

    – vincrichaud
    Mar 27 at 15:36

















  • Not related to your problem, but to simplify your code, instead of using option.equals("q") || option.equals("Q") you can do option.equalsIgnoreCase("q"). See the corresponding doc

    – vincrichaud
    Mar 27 at 15:34











  • You may just put all your code (from the displying of the question, to the end) inside a loop. Use a boolean flag as the condition of your loop. When the user enter q set the flag to false.

    – vincrichaud
    Mar 27 at 15:36
















Not related to your problem, but to simplify your code, instead of using option.equals("q") || option.equals("Q") you can do option.equalsIgnoreCase("q"). See the corresponding doc

– vincrichaud
Mar 27 at 15:34





Not related to your problem, but to simplify your code, instead of using option.equals("q") || option.equals("Q") you can do option.equalsIgnoreCase("q"). See the corresponding doc

– vincrichaud
Mar 27 at 15:34













You may just put all your code (from the displying of the question, to the end) inside a loop. Use a boolean flag as the condition of your loop. When the user enter q set the flag to false.

– vincrichaud
Mar 27 at 15:36





You may just put all your code (from the displying of the question, to the end) inside a loop. Use a boolean flag as the condition of your loop. When the user enter q set the flag to false.

– vincrichaud
Mar 27 at 15:36












1 Answer
1






active

oldest

votes


















0














You mean how to loop the user input? You can use a do-while:



 String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
// do something
else if (option.equalsIgnoreCase("N"))
// do something


// notice we don't need an if for 'Q' here. This loop only determines how many
// times we want to keep going. If it's 'Q', it'll exit the while loop, where
// we then print the size of the list.

while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());


Note I didn't test this code, but it should get you going on the right track.



Also notice that we do not need a System.exit(0) in this case, as the program will just naturally end. Though there are exceptions, you normally do not want to use System.exit(0), and would rather find ways for code to 'finish itself'.






share|improve this answer



























  • Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

    – Osama
    Mar 27 at 20:42











  • @Osama I'm not sure what you mean. What would you like it to do when the user selects n?

    – Tiberiu
    Mar 27 at 20:49











  • Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

    – Tiberiu
    Mar 27 at 20:53












  • Also, I would appreciate if you accepted my answer if you thought it was helpful :)

    – Tiberiu
    Mar 27 at 20:54











  • Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

    – Tiberiu
    Mar 27 at 20:59










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380878%2fis-there-a-way-to-keep-track-of-the-elements-and-to-loop-the-menu%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You mean how to loop the user input? You can use a do-while:



 String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
// do something
else if (option.equalsIgnoreCase("N"))
// do something


// notice we don't need an if for 'Q' here. This loop only determines how many
// times we want to keep going. If it's 'Q', it'll exit the while loop, where
// we then print the size of the list.

while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());


Note I didn't test this code, but it should get you going on the right track.



Also notice that we do not need a System.exit(0) in this case, as the program will just naturally end. Though there are exceptions, you normally do not want to use System.exit(0), and would rather find ways for code to 'finish itself'.






share|improve this answer



























  • Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

    – Osama
    Mar 27 at 20:42











  • @Osama I'm not sure what you mean. What would you like it to do when the user selects n?

    – Tiberiu
    Mar 27 at 20:49











  • Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

    – Tiberiu
    Mar 27 at 20:53












  • Also, I would appreciate if you accepted my answer if you thought it was helpful :)

    – Tiberiu
    Mar 27 at 20:54











  • Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

    – Tiberiu
    Mar 27 at 20:59















0














You mean how to loop the user input? You can use a do-while:



 String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
// do something
else if (option.equalsIgnoreCase("N"))
// do something


// notice we don't need an if for 'Q' here. This loop only determines how many
// times we want to keep going. If it's 'Q', it'll exit the while loop, where
// we then print the size of the list.

while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());


Note I didn't test this code, but it should get you going on the right track.



Also notice that we do not need a System.exit(0) in this case, as the program will just naturally end. Though there are exceptions, you normally do not want to use System.exit(0), and would rather find ways for code to 'finish itself'.






share|improve this answer



























  • Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

    – Osama
    Mar 27 at 20:42











  • @Osama I'm not sure what you mean. What would you like it to do when the user selects n?

    – Tiberiu
    Mar 27 at 20:49











  • Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

    – Tiberiu
    Mar 27 at 20:53












  • Also, I would appreciate if you accepted my answer if you thought it was helpful :)

    – Tiberiu
    Mar 27 at 20:54











  • Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

    – Tiberiu
    Mar 27 at 20:59













0












0








0







You mean how to loop the user input? You can use a do-while:



 String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
// do something
else if (option.equalsIgnoreCase("N"))
// do something


// notice we don't need an if for 'Q' here. This loop only determines how many
// times we want to keep going. If it's 'Q', it'll exit the while loop, where
// we then print the size of the list.

while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());


Note I didn't test this code, but it should get you going on the right track.



Also notice that we do not need a System.exit(0) in this case, as the program will just naturally end. Though there are exceptions, you normally do not want to use System.exit(0), and would rather find ways for code to 'finish itself'.






share|improve this answer















You mean how to loop the user input? You can use a do-while:



 String option;
do
System.out.println("Type A to add a person to the line (# of requests)n"
+ "Type N to do nothing and allow the line to be processedn"
+ "Type Q to quit the applicationn");
option = input.nextLine();

if(option.equalsIgnoreCase("A"))
// do something
else if (option.equalsIgnoreCase("N"))
// do something


// notice we don't need an if for 'Q' here. This loop only determines how many
// times we want to keep going. If it's 'Q', it'll exit the while loop, where
// we then print the size of the list.

while (!option.equalsIgnoreCase("Q"));

System.out.println("Q was chosen. The number of ppl in this queue are " + line.size());


Note I didn't test this code, but it should get you going on the right track.



Also notice that we do not need a System.exit(0) in this case, as the program will just naturally end. Though there are exceptions, you normally do not want to use System.exit(0), and would rather find ways for code to 'finish itself'.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 15:46

























answered Mar 27 at 15:40









TiberiuTiberiu

3764 silver badges20 bronze badges




3764 silver badges20 bronze badges















  • Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

    – Osama
    Mar 27 at 20:42











  • @Osama I'm not sure what you mean. What would you like it to do when the user selects n?

    – Tiberiu
    Mar 27 at 20:49











  • Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

    – Tiberiu
    Mar 27 at 20:53












  • Also, I would appreciate if you accepted my answer if you thought it was helpful :)

    – Tiberiu
    Mar 27 at 20:54











  • Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

    – Tiberiu
    Mar 27 at 20:59

















  • Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

    – Osama
    Mar 27 at 20:42











  • @Osama I'm not sure what you mean. What would you like it to do when the user selects n?

    – Tiberiu
    Mar 27 at 20:49











  • Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

    – Tiberiu
    Mar 27 at 20:53












  • Also, I would appreciate if you accepted my answer if you thought it was helpful :)

    – Tiberiu
    Mar 27 at 20:54











  • Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

    – Tiberiu
    Mar 27 at 20:59
















Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

– Osama
Mar 27 at 20:42





Thank you it works. But I noticed another problem while trying to run it, whenever i try to use "n" and let the queue process itself it only subtracts 1 from the first int ie [5,3,2,1] -> n -> 4(only displays the first int in queue) and if I add another int (6) its going to display [5,3,2,1,6] . any advise?

– Osama
Mar 27 at 20:42













@Osama I'm not sure what you mean. What would you like it to do when the user selects n?

– Tiberiu
Mar 27 at 20:49





@Osama I'm not sure what you mean. What would you like it to do when the user selects n?

– Tiberiu
Mar 27 at 20:49













Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

– Tiberiu
Mar 27 at 20:53






Ok, so let's think like programmers! You have a LinkedList and you'd like to remove the first int in the queue. So if we go here: docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html and check which method allows us to do that (hint, it's pop()). So you would do: int requestsProccessed = line.pop();

– Tiberiu
Mar 27 at 20:53














Also, I would appreciate if you accepted my answer if you thought it was helpful :)

– Tiberiu
Mar 27 at 20:54





Also, I would appreciate if you accepted my answer if you thought it was helpful :)

– Tiberiu
Mar 27 at 20:54













Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

– Tiberiu
Mar 27 at 20:59





Sorry, pop() will remove the last element that was put in. Since you're dealing with a Queue, you will want to use the removeFirst() method.

– Tiberiu
Mar 27 at 20:59








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380878%2fis-there-a-way-to-keep-track-of-the-elements-and-to-loop-the-menu%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?