Advertisement
Egonau

Untitled

Feb 27th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. static int performEcholocation (final EcholocationManager manager) throws EcholocationException,LocatorConnectionException{
  2.  
  3. int count = 0;
  4. while(true){
  5. try{
  6. manager.connectLocator();
  7. break;
  8. }
  9. catch (LocatorConnectionException e){
  10. count+=1;
  11. if (count>4){
  12. throw e;
  13. }
  14. }
  15. }
  16. int[] arr = new int[100];
  17. boolean isDisconnected = false;
  18. try{
  19. for (int i = 0;i<100;++i){
  20. int elem = manager.locate(i+1);
  21. arr[i] = elem;
  22. }
  23. }
  24. catch(EcholocationException err){
  25. isDisconnected = true;
  26. try{
  27. manager.disconnectLocator();
  28. }
  29. catch(LocatorConnectionException ignored){
  30. }
  31. throw err;
  32. }
  33. finally{
  34. if (!isDisconnected){
  35. try{
  36. manager.disconnectLocator();
  37. }
  38. catch(LocatorConnectionException ignored){
  39. }
  40. }
  41. }
  42. int res = arr[0];
  43. for (int i = 1;i<arr.length;++i){
  44. res^=arr[i];
  45. }
  46. return res;
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement