/
alexShibanov
/
556677
Обзор
Документация
Войти
/
alexShibanov
/
556677
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
OpenWeatherMap.java
38 строк
1 KB
Suresh
Made a wheather Map
18 окт 2023, 17:02
Не верифицирован
18 окт 2023, 17:02
e7b184f
Код
Авторство
О чём код?
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class WeatherApp { public static void main(String[] args) { String apiKey = "YOUR_API_KEY"; // Replace with your OpenWeatherMap API key String city = "New York"; // Replace with the desired city try { String apiUrl = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + apiKey; URL url = new URL(apiUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuilder response = new StringBuilder(); while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); // Parse and display the weather information String weatherData = response.toString(); System.out.println("Weather Data:"); System.out.println(weatherData); } catch (IOException e) { e.printStackTrace(); } } }