Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int performEcholocation (final EcholocationManager manager) throws EcholocationException,LocatorConnectionException{
- int count = 0;
- while(true){
- try{
- manager.connectLocator();
- break;
- }
- catch (LocatorConnectionException e){
- count+=1;
- if (count>4){
- throw e;
- }
- }
- }
- int[] arr = new int[100];
- boolean isDisconnected = false;
- try{
- for (int i = 0;i<100;++i){
- int elem = manager.locate(i+1);
- arr[i] = elem;
- }
- }
- catch(EcholocationException err){
- isDisconnected = true;
- try{
- manager.disconnectLocator();
- }
- catch(LocatorConnectionException ignored){
- }
- throw err;
- }
- finally{
- if (!isDisconnected){
- try{
- manager.disconnectLocator();
- }
- catch(LocatorConnectionException ignored){
- }
- }
- }
- int res = arr[0];
- for (int i = 1;i<arr.length;++i){
- res^=arr[i];
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement