Advertisement
Egonau

Untitled

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