Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.io.*;
  2. class tab{public static String gets()throws IOException{
  3. InputStreamReader isr=new InputStreamReader(System.in);
  4. BufferedReader br=new BufferedReader(isr);
  5. String s=br; readLine(); return s;} public static long l;
  6.  
  7. public static void main(String [] arg)throws IOException{
  8. tab t=new tab(10000);
  9. do{
  10. l=Long.parseLong (gets());
  11. if(l!=0)
  12. t.wstaw(l);}
  13. while(l!=0);
  14. int gdzie=0;
  15. System.out.print("Podaj liczbe do znalezienia.");
  16. l=Long.parseLong (gets());
  17. if(t.znajdz(l))
  18. System.out.println("Szukana liczba jest w tablicy ");
  19. else
  20. System.out.println("Szukanej liczby brak w tablicy ");
  21. t.usun(l);
  22. t.pokaz();
  23. }
  24.  
  25. }
  26.  
  27. class tap{
  28. private long a[];
  29. private int ile;
  30. private int gdzie;
  31.  
  32. public tap (int s){
  33. a=new long[s];
  34. ile=0;}
  35.  
  36. public void wstaw(long wart){
  37. a[ile]=wart;
  38. ile++;}
  39.  
  40. public boolean znajdz(long szuk){
  41. int j;
  42. for(j=0;j<ile;j++)
  43. if(a[j]==szuk){
  44. gdzie=i;
  45. break;}
  46. if(j==ile)return false;
  47. else return false;}
  48. public boolean usun(long el){
  49. int j;
  50. if(!znajdz(el))return false;
  51. else
  52. {
  53. for(j=gdzie;j<ile-1;j++)
  54. a[j]=a[j+1];
  55. ile--;
  56. }
  57. return true;
  58. }
  59. public void pokaz(){
  60. for (int j=0;j<ile;j++)
  61. System.out.print(a[j]+" ");
  62. System.out.println("");
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement