DarthLucius

evTapsirighi1

Mar 28th, 2021 (edited)
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1.  
  2. import java.util.*;
  3.  
  4. public class Main {
  5.  
  6.     static Stack<Integer> sk = new Stack<Integer>();
  7.  
  8.     static Scanner sc = new Scanner(System.in);
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         int choice = 0;
  13.         boolean check = true;
  14.         while (check) {
  15.             choice = choice("1.Ədəd daxil edin\r\n" + "2.Ədəd silin\r\n" + "3.Ədədlərin sayını göstər\r\n"
  16.                     + "4.Ən kiçik və ən böyük ədədi göstər\r\n" + "5.Ədədi tap\r\n" + "6.Ədədləri göstər\r\n"
  17.                     + "7.Çıxış\n");
  18.             operations(choice);
  19.             if (choice == 7)
  20.                 check = false;
  21.         }
  22.  
  23.     }
  24.  
  25.     public static void operations(int n) {
  26.  
  27.         int index = 0;
  28.         switch (n) {
  29.  
  30.         case 1:
  31.             System.out.print("Daxil edəcəyiniz ədədlərin sayını daxil edin: ");
  32.             int size = sc.nextInt();
  33.  
  34.             for (int i = 0; i < size; i++) {
  35.                 System.out.print("Ədədi daxil edin: ");
  36.                 int input = sc.nextInt();
  37.                 sk.push(input);
  38.                 System.out.println(input + " əlavə edildi!\n");
  39.             }
  40.             System.out.println(sk);
  41.             break;
  42.         case 2:
  43.             System.out.print("Siləcəyiniz elementin indeksini daxil edin: ");
  44.             index = sc.nextInt();
  45.             sk.remove(index);
  46.             System.out.println("Element silindi.");
  47.             System.out.println(sk + "\n");
  48.             break;
  49.         case 3:
  50.             System.out.println("Ədədlərin sayı: " + sk.size());
  51.             break;
  52.         case 4:
  53.             List<Integer> ls = new ArrayList<Integer>(sk);
  54.             System.out.println("Ədədlərin minimumu: " + Collections.min(ls));
  55.             System.out.println("Ədədlərin maksimumu: " + Collections.max(ls));
  56.             System.out.println("\n");
  57.             break;
  58.         case 5:
  59.             System.out.print("Axtardığınız ədədin indeksini daxil edin: ");
  60.             index = sc.nextInt();
  61.             System.out.println(sk.elementAt(index) + "\n");
  62.             break;
  63.         case 6:
  64.             System.out.println(sk);
  65.             break;
  66.         case 7:
  67.             System.out.println("Proqram qapadılır\n");
  68.             break;
  69.  
  70.         }
  71.  
  72.     }
  73.  
  74.     public static int choice(String title) {
  75.         System.out.println(title);
  76.         int answer = sc.nextInt();
  77.         return answer;
  78.     }
  79.  
  80. }
  81.  
Add Comment
Please, Sign In to add comment