How to store variable value into an array inside a for loop in java












-5















I need to calculate distance between 2 (points) latitudes and longitudes, one point is in an array and other is sent as parameter. The calculated distance should store in another array so that I can calculate minimum distance in an array. The problem is am not able to store that calculated distance into an array so plzz do help me out.



 @Override
public MinimumDistanceModel getMinimumDistance(double latitude, double longitude) throws Exception {
try {

double lon1 = longitude;
double lat1 = latitude;
List<MinimumDistanceDomain> minDistDomain = minimumDistanceDAO.getFranchiseDetails();
for(MinimumDistanceDomain minimumDistanceDomain : minDistDomain) {
double lat2 = minimumDistanceDomain.getLatitude();
double lon2 = minimumDistanceDomain.getLongitude();

MinimumDistanceModel minimumDistanceModel = new MinimumDistanceModel();
minimumDistanceModel.setDistance1(CommonUtils.distance(lat1, lat2, lon1, lon2));

System.out.println(minimumDistanceModel.getDistance1());

Double distance = minimumDistanceModel.getDistance1();

}


} catch (Exception e) {
logger.info("Exception getMinimumDistance in DistanceServiceImpl" + e.getMessage());
}

return null;

}


`



Result of above code: It's just printing the distances between those 2 points, how do I return those distances in an array










share|improve this question




















  • 1





    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

    – Joe C
    Nov 22 '18 at 7:52






  • 3





    Why do you need to store things in an array to calculate the minimum? Just keep the minimum you have seen so far in a variable.

    – Andy Turner
    Nov 22 '18 at 7:52











  • @JoeC i have updated question with current behaviour

    – Bhavyashree N L
    Nov 22 '18 at 8:01











  • @AndyTurner How to keep the minimum without storing it into an array

    – Bhavyashree N L
    Nov 22 '18 at 8:02











  • Like Andy mentioned you store it in a variable, the same way you store values in lon1 and lat1

    – Joakim Danielson
    Nov 22 '18 at 8:07
















-5















I need to calculate distance between 2 (points) latitudes and longitudes, one point is in an array and other is sent as parameter. The calculated distance should store in another array so that I can calculate minimum distance in an array. The problem is am not able to store that calculated distance into an array so plzz do help me out.



 @Override
public MinimumDistanceModel getMinimumDistance(double latitude, double longitude) throws Exception {
try {

double lon1 = longitude;
double lat1 = latitude;
List<MinimumDistanceDomain> minDistDomain = minimumDistanceDAO.getFranchiseDetails();
for(MinimumDistanceDomain minimumDistanceDomain : minDistDomain) {
double lat2 = minimumDistanceDomain.getLatitude();
double lon2 = minimumDistanceDomain.getLongitude();

MinimumDistanceModel minimumDistanceModel = new MinimumDistanceModel();
minimumDistanceModel.setDistance1(CommonUtils.distance(lat1, lat2, lon1, lon2));

System.out.println(minimumDistanceModel.getDistance1());

Double distance = minimumDistanceModel.getDistance1();

}


} catch (Exception e) {
logger.info("Exception getMinimumDistance in DistanceServiceImpl" + e.getMessage());
}

return null;

}


`



Result of above code: It's just printing the distances between those 2 points, how do I return those distances in an array










share|improve this question




















  • 1





    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

    – Joe C
    Nov 22 '18 at 7:52






  • 3





    Why do you need to store things in an array to calculate the minimum? Just keep the minimum you have seen so far in a variable.

    – Andy Turner
    Nov 22 '18 at 7:52











  • @JoeC i have updated question with current behaviour

    – Bhavyashree N L
    Nov 22 '18 at 8:01











  • @AndyTurner How to keep the minimum without storing it into an array

    – Bhavyashree N L
    Nov 22 '18 at 8:02











  • Like Andy mentioned you store it in a variable, the same way you store values in lon1 and lat1

    – Joakim Danielson
    Nov 22 '18 at 8:07














-5












-5








-5








I need to calculate distance between 2 (points) latitudes and longitudes, one point is in an array and other is sent as parameter. The calculated distance should store in another array so that I can calculate minimum distance in an array. The problem is am not able to store that calculated distance into an array so plzz do help me out.



 @Override
public MinimumDistanceModel getMinimumDistance(double latitude, double longitude) throws Exception {
try {

double lon1 = longitude;
double lat1 = latitude;
List<MinimumDistanceDomain> minDistDomain = minimumDistanceDAO.getFranchiseDetails();
for(MinimumDistanceDomain minimumDistanceDomain : minDistDomain) {
double lat2 = minimumDistanceDomain.getLatitude();
double lon2 = minimumDistanceDomain.getLongitude();

MinimumDistanceModel minimumDistanceModel = new MinimumDistanceModel();
minimumDistanceModel.setDistance1(CommonUtils.distance(lat1, lat2, lon1, lon2));

System.out.println(minimumDistanceModel.getDistance1());

Double distance = minimumDistanceModel.getDistance1();

}


} catch (Exception e) {
logger.info("Exception getMinimumDistance in DistanceServiceImpl" + e.getMessage());
}

return null;

}


`



Result of above code: It's just printing the distances between those 2 points, how do I return those distances in an array










share|improve this question
















I need to calculate distance between 2 (points) latitudes and longitudes, one point is in an array and other is sent as parameter. The calculated distance should store in another array so that I can calculate minimum distance in an array. The problem is am not able to store that calculated distance into an array so plzz do help me out.



 @Override
public MinimumDistanceModel getMinimumDistance(double latitude, double longitude) throws Exception {
try {

double lon1 = longitude;
double lat1 = latitude;
List<MinimumDistanceDomain> minDistDomain = minimumDistanceDAO.getFranchiseDetails();
for(MinimumDistanceDomain minimumDistanceDomain : minDistDomain) {
double lat2 = minimumDistanceDomain.getLatitude();
double lon2 = minimumDistanceDomain.getLongitude();

MinimumDistanceModel minimumDistanceModel = new MinimumDistanceModel();
minimumDistanceModel.setDistance1(CommonUtils.distance(lat1, lat2, lon1, lon2));

System.out.println(minimumDistanceModel.getDistance1());

Double distance = minimumDistanceModel.getDistance1();

}


} catch (Exception e) {
logger.info("Exception getMinimumDistance in DistanceServiceImpl" + e.getMessage());
}

return null;

}


`



Result of above code: It's just printing the distances between those 2 points, how do I return those distances in an array







java arrays






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 7:59







Bhavyashree N L

















asked Nov 22 '18 at 7:50









Bhavyashree N LBhavyashree N L

11




11








  • 1





    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

    – Joe C
    Nov 22 '18 at 7:52






  • 3





    Why do you need to store things in an array to calculate the minimum? Just keep the minimum you have seen so far in a variable.

    – Andy Turner
    Nov 22 '18 at 7:52











  • @JoeC i have updated question with current behaviour

    – Bhavyashree N L
    Nov 22 '18 at 8:01











  • @AndyTurner How to keep the minimum without storing it into an array

    – Bhavyashree N L
    Nov 22 '18 at 8:02











  • Like Andy mentioned you store it in a variable, the same way you store values in lon1 and lat1

    – Joakim Danielson
    Nov 22 '18 at 8:07














  • 1





    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

    – Joe C
    Nov 22 '18 at 7:52






  • 3





    Why do you need to store things in an array to calculate the minimum? Just keep the minimum you have seen so far in a variable.

    – Andy Turner
    Nov 22 '18 at 7:52











  • @JoeC i have updated question with current behaviour

    – Bhavyashree N L
    Nov 22 '18 at 8:01











  • @AndyTurner How to keep the minimum without storing it into an array

    – Bhavyashree N L
    Nov 22 '18 at 8:02











  • Like Andy mentioned you store it in a variable, the same way you store values in lon1 and lat1

    – Joakim Danielson
    Nov 22 '18 at 8:07








1




1





Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

– Joe C
Nov 22 '18 at 7:52





Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.

– Joe C
Nov 22 '18 at 7:52




3




3





Why do you need to store things in an array to calculate the minimum? Just keep the minimum you have seen so far in a variable.

– Andy Turner
Nov 22 '18 at 7:52





Why do you need to store things in an array to calculate the minimum? Just keep the minimum you have seen so far in a variable.

– Andy Turner
Nov 22 '18 at 7:52













@JoeC i have updated question with current behaviour

– Bhavyashree N L
Nov 22 '18 at 8:01





@JoeC i have updated question with current behaviour

– Bhavyashree N L
Nov 22 '18 at 8:01













@AndyTurner How to keep the minimum without storing it into an array

– Bhavyashree N L
Nov 22 '18 at 8:02





@AndyTurner How to keep the minimum without storing it into an array

– Bhavyashree N L
Nov 22 '18 at 8:02













Like Andy mentioned you store it in a variable, the same way you store values in lon1 and lat1

– Joakim Danielson
Nov 22 '18 at 8:07





Like Andy mentioned you store it in a variable, the same way you store values in lon1 and lat1

– Joakim Danielson
Nov 22 '18 at 8:07












1 Answer
1






active

oldest

votes


















0














The below code will assign a value for each iteration, basically what I am saying is since you have the lat and long you can do a calc within each iteration to get the distance instead of using common utils . Key line here is this one testArray[i]=i;



 var lat ; 
var long;
var distance;
int testDistanceArray = new int[50];

for (int i = 0; i < testDistanceArray.length; i++) {
testDistanceArray[i]= lat -long ;
distance = testDistanceArray[i]
// that will give you the distance for each iteration
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426141%2fhow-to-store-variable-value-into-an-array-inside-a-for-loop-in-java%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The below code will assign a value for each iteration, basically what I am saying is since you have the lat and long you can do a calc within each iteration to get the distance instead of using common utils . Key line here is this one testArray[i]=i;



     var lat ; 
    var long;
    var distance;
    int testDistanceArray = new int[50];

    for (int i = 0; i < testDistanceArray.length; i++) {
    testDistanceArray[i]= lat -long ;
    distance = testDistanceArray[i]
    // that will give you the distance for each iteration
    }





    share|improve this answer






























      0














      The below code will assign a value for each iteration, basically what I am saying is since you have the lat and long you can do a calc within each iteration to get the distance instead of using common utils . Key line here is this one testArray[i]=i;



       var lat ; 
      var long;
      var distance;
      int testDistanceArray = new int[50];

      for (int i = 0; i < testDistanceArray.length; i++) {
      testDistanceArray[i]= lat -long ;
      distance = testDistanceArray[i]
      // that will give you the distance for each iteration
      }





      share|improve this answer




























        0












        0








        0







        The below code will assign a value for each iteration, basically what I am saying is since you have the lat and long you can do a calc within each iteration to get the distance instead of using common utils . Key line here is this one testArray[i]=i;



         var lat ; 
        var long;
        var distance;
        int testDistanceArray = new int[50];

        for (int i = 0; i < testDistanceArray.length; i++) {
        testDistanceArray[i]= lat -long ;
        distance = testDistanceArray[i]
        // that will give you the distance for each iteration
        }





        share|improve this answer















        The below code will assign a value for each iteration, basically what I am saying is since you have the lat and long you can do a calc within each iteration to get the distance instead of using common utils . Key line here is this one testArray[i]=i;



         var lat ; 
        var long;
        var distance;
        int testDistanceArray = new int[50];

        for (int i = 0; i < testDistanceArray.length; i++) {
        testDistanceArray[i]= lat -long ;
        distance = testDistanceArray[i]
        // that will give you the distance for each iteration
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 8:24

























        answered Nov 22 '18 at 8:13









        ZidaneZidane

        4442821




        4442821
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426141%2fhow-to-store-variable-value-into-an-array-inside-a-for-loop-in-java%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$