Advertisement
DarthLucius

Ev tapşırığı 2.1

Apr 3rd, 2021
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class EvTapsirigi2_1 {
  4.  
  5.     static Queue<Integer> qe = new LinkedList<>();
  6.     static Scanner sc = new Scanner(System.in);
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         boolean check = true;
  11.         int choice;
  12.  
  13.         while (check) {
  14.  
  15.             choice = choice("1.Ədəd daxil edin\r\n" + "2.Ədəd silin\r\n" + "3.Öndəki ədədi göstər\r\n"
  16.                     + "4.Ədədləri göstər\r\n" + "5.Çıxış\r\n");
  17.             operations(choice);
  18.  
  19.             if (choice == 5)
  20.                 check = false;
  21.  
  22.         }
  23.  
  24.     }
  25.  
  26.     public static void operations(int n) {
  27.  
  28.         switch (n) {
  29.  
  30.         case 1:
  31.             System.out.print("Daxil edəcəyiniz ədədlərin sayı: ");
  32.             int size = sc.nextInt();
  33.             System.out.print("Ədəd(lər)i daxil edin: ");
  34.             for (int i = 0; i < size; i++) {
  35.                 int input = sc.nextInt();
  36.                 qe.offer(input);
  37.                 System.out.println(input + " əlavə edildi!\n");
  38.             }
  39.             break;
  40.         case 2:
  41.             qe.poll();
  42.             System.out.println("Silindi!");
  43.             System.out.println(qe);
  44.             break;
  45.         case 3:
  46.             System.out.print("Birinci indeksdəki ədəd: ");
  47.             System.out.println(qe.peek());
  48.             System.out.println("\n");
  49.             break;
  50.         case 4:
  51.             System.out.println(qe);
  52.             break;
  53.         case 5:
  54.             System.out.println("Proqram qapadılır...\n");
  55.             break;
  56.  
  57.         }
  58.  
  59.     }
  60.  
  61.     public static int choice(String title) {
  62.  
  63.         System.out.println(title);
  64.         int answer = sc.nextInt();
  65.         return answer;
  66.  
  67.     }
  68.  
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement