Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class EvTapsirigi2_2 {
- static Scanner sc = new Scanner(System.in);
- static Deque<Integer> dq = new ArrayDeque<>();
- public static void main(String[] args) {
- boolean check = true;
- int choice;
- while (check) {
- choice = choice(
- "1.Ədədi əvvələ daxil edin\r\n" + "2.Ədədi axıra daxil edin\r\n" + "3.Birinci ədədi silin\r\n"
- + "4.Axırdakı ədədi silin\r\n" + "5.Ədədləri göstər\r\n" + "6.Çıxış\r\n");
- operations(choice);
- if (choice == 6)
- check = false;
- }
- }
- public static void operations(int n) {
- int input;
- switch (n) {
- case 1:
- System.out.print("Ədəd: ");
- input = sc.nextInt();
- dq.addFirst(input);
- System.out.println(input + " əvvələ əlavə edildi!\n");
- break;
- case 2:
- System.out.print("Ədəd: ");
- input = sc.nextInt();
- dq.addLast(input);
- System.out.println(input + " sona əlavə edildi!\n");
- break;
- case 3:
- dq.removeFirst();
- System.out.println("İlk ədəd silindi!\n");
- break;
- case 4:
- dq.removeLast();
- System.out.println("İlk ədəd silindi!\n");
- break;
- case 5:
- System.out.print("Ədədlər: ");
- for (int i : dq) {
- System.out.print(i + " ");
- }
- System.out.println("\n");
- }
- }
- public static int choice(String title) {
- System.out.println(title);
- int answer = sc.nextInt();
- return answer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement