Application

Report a typo

Implement the printElement() method to print the n-th element of the queue.

Sample Input 1:

90
100
80
70
1

Sample Output 1:

70
Write 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
}
}
___

Create a free account to access the full topic