Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab04;
- import java.util.Hashtable;
- /**
- *
- * @author Nan Mihai
- */
- public class HSet extends Hashtable{
- public void add(Object o) {
- super.put(o, o);
- }
- @Override
- public boolean contains(Object o) {
- return super.contains(o);
- }
- public int size() {
- return super.size();
- }
- public String toString() {
- return super.toString();
- }
- public void afisare(int x) {
- boolean ok;
- ok = this.contains(x);
- if(ok) {
- System.out.println("Elementul " + x + " se afla in HSet!");
- } else {
- System.out.println("Elementul " + x + " nu se afla in HSet!");
- }
- }
- public static void main( String args[] ) {
- boolean ok;
- int x;
- x = 0;
- HSet M = new HSet();
- for(int i = 0; i < 100; i++) {
- x = (int) Math.round(Math.random()*1000);
- M.add(x);
- }
- System.out.println(M);
- M.afisare(x);
- M.afisare(158);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment