Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- static Stack<Integer> sk = new Stack<Integer>();
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- int choice = 0;
- boolean check = true;
- while (check) {
- 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"
- + "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"
- + "7.Çıxış\n");
- operations(choice);
- if (choice == 7)
- check = false;
- }
- }
- public static void operations(int n) {
- int index = 0;
- switch (n) {
- case 1:
- System.out.print("Daxil edəcəyiniz ədədlərin sayını daxil edin: ");
- int size = sc.nextInt();
- for (int i = 0; i < size; i++) {
- System.out.print("Ədədi daxil edin: ");
- int input = sc.nextInt();
- sk.push(input);
- System.out.println(input + " əlavə edildi!\n");
- }
- System.out.println(sk);
- break;
- case 2:
- System.out.print("Siləcəyiniz elementin indeksini daxil edin: ");
- index = sc.nextInt();
- sk.remove(index);
- System.out.println("Element silindi.");
- System.out.println(sk + "\n");
- break;
- case 3:
- System.out.println("Ədədlərin sayı: " + sk.size());
- break;
- case 4:
- List<Integer> ls = new ArrayList<Integer>(sk);
- System.out.println("Ədədlərin minimumu: " + Collections.min(ls));
- System.out.println("Ədədlərin maksimumu: " + Collections.max(ls));
- System.out.println("\n");
- break;
- case 5:
- System.out.print("Axtardığınız ədədin indeksini daxil edin: ");
- index = sc.nextInt();
- System.out.println(sk.elementAt(index) + "\n");
- break;
- case 6:
- System.out.println(sk);
- break;
- case 7:
- System.out.println("Proqram qapadılır\n");
- break;
- }
- }
- public static int choice(String title) {
- System.out.println(title);
- int answer = sc.nextInt();
- return answer;
- }
- }
Add Comment
Please, Sign In to add comment