Skip to content
Advertisement

create a sub list of elements based on user input

I wrote the code below, where from an initialized list of countries the method will return all the countries who have a longitude of >= 5, the code works but now I want the method to return the name of countries that are close to String D within a 5 degrees range of longitude.

I tried implementing the scanner as shown below but I still get countries that have longitude higher than 5. how can I make the method return the name of countries based on the user input.

JavaScript

Advertisement

Answer

Correct your if statement.

You are writing following …

JavaScript

The “country.CountryName.equals(D)” part returns true or false. So you are checking if CountriesDistance not contains true/false AND if the longitude of the country is greater or equal to 5.

I guess you ment:

JavaScript

I initialized baseCountry like this:

JavaScript

In this case I got the name of the Country by calling getName() which I implemented like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement