Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Zbior;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author MaxSylverWolf
- */
- public class Zbiory implements IZbior{
- public int[] tab = new int[100];
- public int licznik = 0;
- public void dodaj(int nowy) {
- tab[licznik++] = nowy;
- }
- public void wypisz() {
- for(int i=0; i<100; i++)
- System.out.println("["+tab[i]+"]");
- }
- static Scanner skanuj = new Scanner(System.in);
- static Random losuj = new Random();
- public static void main(String[] args) {
- Zbiory zbior = new Zbiory();
- System.out.println("Podaj ilość elementów w tablicy: ");
- int n;
- n = skanuj.nextInt();
- int[] tablica = new int[n];
- System.out.println("Podaj je");
- for(int i=0;i<n;i++) {
- tablica[i] = skanuj.nextInt();
- }
- System.out.println("");
- wypisz();
- System.out.println("Co chcesz zrobić?");
- System.out.println("1 - Dodaj element do tablicy");
- System.out.println("2 - Usuń element z tablicy");
- System.out.println("3 - Zwróc rozmiar tablicy");
- System.out.println("4 - Sprawdź czy zawiera podany element");
- System.out.println("5 - Wypisz tablice");
- int licznik = skanuj.nextInt();
- switch(licznik) {
- case 1: {
- System.out.println("Wprowadź element: ");
- int nowy = skanuj.nextInt();
- tablica[n++] = nowy;
- } break;
- case 2: {
- System.out.println("Który element chcesz usunąć? Podaj tą liczbę");
- int element = skanuj.nextInt();
- for(int i=0;i<n;i++) {
- if(tablica[i]==element) {
- tablica[i]=tablica[n];
- n--; } } } break;
- case 3: {
- System.out.println("Rozmiar tablicy to: "+n--);
- } break;
- case 4: {
- System.out.println("Podaj element, który chcesz sprawdzić czy istnieje: ");
- int sprawdz = skanuj.nextInt();
- for(int i =0 ; i<n;i++){
- if(sprawdz==tablica[i])System.out.println("Zawiera ten element");
- else System.out.println("Nie zawiera tego elementu");
- }
- } break;
- case 5: System.out.println(tablica); break;
- }
- skanuj.close();
- }
- @Override
- public void usun(int element) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public int rozmiar() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public boolean czyZawiera(int element) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public void wczytaj(String filename) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public boolean czyRowne(IZbior drugi) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public IZbior suma(IZbior drugi) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public IZbior roznica(IZbior drugi) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public IZbior przeciecie(IZbior drugi) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- @Override
- public IZbior roznicaSymetryczna(IZbior drugi) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement