Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. /**
  2. * Created by MikeDabrowski on 03.12.2016
  3. * Project name: test
  4. */
  5. public class ElementFinder {
  6. /* definicja pol */
  7. int[] myArray = new int[6];
  8.  
  9. /* konstruktory */
  10. public ElementFinder() {
  11. this.myArray[0] = 3;
  12. this.myArray[1] = 5;
  13. this.myArray[2] = 2;
  14. this.myArray[3] = 0;
  15. this.myArray[4] = 7;
  16. this.myArray[5] = 12;
  17. }
  18.  
  19. public ElementFinder(int[] myArray) {
  20. this.myArray = myArray;
  21. }
  22.  
  23. /* metody klasy*/
  24. public int findElement(int x){
  25. int requestedValue = x;
  26.  
  27. for(int i = 0; i < Array.getLength(myArray); i++){
  28. if(myArray[i] == x)
  29. return i;
  30. else return -1;
  31. }
  32. //tu nie masz returna wiec dodaje
  33. return 0;
  34. }
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement