Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: Java | Size: 0.83 KB | Hits: 95 | Expires: Never
Copy text to clipboard
  1. import java.util.*;
  2.  
  3. public class iterator3 implements Iterator{
  4. int tab[] = new int[100];
  5. public int current,k,p;
  6. public void GenerujTablice(){
  7. for (int i=0; i<100; i++){
  8. tab[i] = (int)(Math.random()*100);
  9. System.out.print(" "+tab[i]);
  10. if ( i % 10 == 0){
  11. System.out.println("");
  12. }
  13. }
  14. }
  15.  
  16.  
  17.  
  18. public void remove(){
  19. try{}
  20. catch(UnsupportedOperationException e){
  21. System.err.println("Not supported.");
  22. }
  23. }
  24.  
  25. public void IterujTablice(int pe, int ka){
  26. //Iterator it = new iterator3();
  27. k=ka;
  28. p=pe;
  29. current=pe;
  30. Iterator it = new iterator3();
  31. while(it.hasNext()) {
  32. it.next();
  33. System.out.println("current"+current+" "+tab[current]);
  34. }
  35. }
  36. public boolean hasNext(){
  37. if(current < 100 ){
  38. return true;} else {
  39. return false;
  40. }
  41. }
  42. public Object next(){
  43. if(current < 99) {
  44. current=current+k;}
  45. return (Integer)tab[current];
  46. }
  47. }