This code is working but i want my added words to show in vertical because its output is shown in horizontal if two or more words is inserted. Can you help me to improve my program? Here are the codes...
/**
* Write a description of class Stacks here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
import java.io.*;
public class Queues_Lab2 {
public static void main (String args[]) {
Scanner s = new Scanner(System.in);
LinkedList st = new LinkedList();
int count = 0;
int y = -1;
boolean b = false, checker = false;
while(!checker){
System.out.println("\n\t\t\t_ M _ E _ N _ U _");
System.out.println("[1] Enqueue");
System.out.println("[2] Dequeue");
System.out.println("[3] View");
System.out.println("[4] Front");
System.out.println("[5] Rear");
System.out.println("[6] Exit");
System.out.print("CHOICE: ");
String choice = s.next();
if(choice.equals("1")){
System.out.print("Enter word: ");
if(count == 10) {
System.out.println("Overflow Not allowed!");
}
else{
String enterWord = s.next();
st.add(enterWord);
System.out.print( st+ "is Inserted");
count++;
}
}
else if(choice.equals("2")){
if(count == 0) {
System.out.println("Underflow Not allowed!");
}
else{
System.out.println(st.pop());
System.out.println("Queue Elements: \n" + st);
}
}
else if(choice.equals("3")){
System.out.println("Queue Elements: \n" +st );
}
else if(choice.equals("4")){
System.out.println("Front Elements: \n" +st.peek());
}
else if(choice.equals("5")){
int loc = st.size()-1;
System.out.print("Rear Elements: \n" +st.get(loc));
}
else if(choice.equals("6")){
System.out.println("ByeBye! :)");
System.exit(0);
}
else{
System.out.println("Wrong Choice!!");
}
}
}
}