Question: Variable codesQueue is a Queue of type Character. Characters are read from input and are added to codesQueue until ' Z ' is read. Complete
Variable codesQueue is a Queue of type Character. Characters are read from input and are added to codesQueue until Z is read. Complete the loop to remove and output the element at the head of codesQueue while both of the following conditions are true:
codesQueue is not empty.
The value at the head of codesQueue is not equal to W
Ex: If the input is X T V L W Z then the output is:
Screened code: X
Screened code: T
Screened code: V
Screened code: L
Alert: Code W is now at the front of the queue
import java.util.Queue;
import java.util.Scanner;
import java.util.LinkedList;
public class FirstInCodesQueue
public static void mainString args
Scanner scnr new ScannerSystemin;
Queue codesQueue new LinkedList;
char codeValue;
codeValue scnrnextcharAt;
while codeValue Z
codesQueue.addcodeValue;
codeValue scnrnextcharAt;
while
Your code goes here
System.out.printlnScreened code: codesQueue.poll;
if codesQueuepeek null
System.out.printlnAll codes screened";
else
System.out.printAlert: Code codesQueue.peek;
System.out.println is now at the front of the queue";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
