Implement the printElement() method to print the n-th element of the queue.
PriorityQueue
Application
Report a typo
Sample Input 1:
90
100
80
70
1Sample Output 1:
70Write a program in Java 17
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Queue<Integer> queue = createQueue(scanner);
printElement(queue, scanner.nextInt());
}
public static Queue<Integer> createQueue(Scanner scanner) {
Queue<Integer> queue = new PriorityQueue();
queue.add(scanner.nextInt());
queue.add(scanner.nextInt());
queue.add(scanner.nextInt());
queue.add(scanner.nextInt());
return queue;
}
public static void printElement(Queue<Integer> queue, int n) {
// write your code here
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.