forked from Jasmine-21/Java-FOP
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtail5th.java
More file actions
28 lines (26 loc) · 750 Bytes
/
tail5th.java
File metadata and controls
28 lines (26 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class tail5th {
public static void main(String[] args) {
// TODO Auto-generated method stub
Queue<Integer> queue=new LinkedList<Integer>();
Scanner s=new Scanner(System.in);
int n=s.nextInt();
while(n-->0)
{
queue.add(s.nextInt());
}
printFifthElementFromEnd(queue);
}
static void printFifthElementFromEnd(Queue<Integer> queue) {
int n = queue.size();
if (n < 5)
System.out.println("There are no enough elements in the queue");
else {
while (queue.size() > 5)
queue.remove();
System.out.println(queue.peek());
}
}
}