Advertisement
DarthLucius

Ev tapşırığı 2.2

Apr 3rd, 2021
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class EvTapsirigi2_2 {
  4.  
  5.     static Scanner sc = new Scanner(System.in);
  6.     static Deque<Integer> dq = new ArrayDeque<>();
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         boolean check = true;
  11.         int choice;
  12.  
  13.         while (check) {
  14.  
  15.             choice = choice(
  16.                     "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"
  17.                             + "4.Axırdakı ədədi silin\r\n" + "5.Ədədləri göstər\r\n" + "6.Çıxış\r\n");
  18.             operations(choice);
  19.  
  20.             if (choice == 6)
  21.                 check = false;
  22.  
  23.         }
  24.  
  25.     }
  26.  
  27.     public static void operations(int n) {
  28.  
  29.         int input;
  30.  
  31.         switch (n) {
  32.  
  33.         case 1:
  34.             System.out.print("Ədəd: ");
  35.             input = sc.nextInt();
  36.             dq.addFirst(input);
  37.             System.out.println(input + " əvvələ əlavə edildi!\n");
  38.             break;
  39.         case 2:
  40.             System.out.print("Ədəd: ");
  41.             input = sc.nextInt();
  42.             dq.addLast(input);
  43.             System.out.println(input + " sona əlavə edildi!\n");
  44.             break;
  45.         case 3:
  46.             dq.removeFirst();
  47.             System.out.println("İlk ədəd silindi!\n");
  48.             break;
  49.         case 4:
  50.             dq.removeLast();
  51.             System.out.println("İlk ədəd silindi!\n");
  52.             break;
  53.         case 5:
  54.             System.out.print("Ədədlər: ");
  55.             for (int i : dq) {
  56.                 System.out.print(i + " ");
  57.             }
  58.             System.out.println("\n");
  59.  
  60.         }
  61.  
  62.     }
  63.  
  64.     public static int choice(String title) {
  65.  
  66.         System.out.println(title);
  67.         int answer = sc.nextInt();
  68.         return answer;
  69.  
  70.     }
  71.  
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement