24小時查的到,但是3天七天卻查不到信息,這是為啥,明明是同樣的代碼
if(a==1){
System.out.print("請輸入城市名稱查詢24小時天氣預報:");
String city=in.next();
? ? WeatherUtils weatherUtils =new WeatherUtilsImpl();
? ? List<HourWeather> weatherList=weatherUtils.w24h("0d8abeeafc364b5aaa73b7e52ceb83ba", city);
// ? ? System.out.println(weatherList);
? ? if(weatherList.size()==0){
? ? System.out.println("未查詢到數(shù)據(jù)");
? ? }else{
? ? for(HourWeather hourWeather:weatherList){
? ? String template="%s月%s日%s時|%-3s|%-20s|%-8s|%-4s";
String row=String.format(template, new String[]{
? ? hourWeather.getMonth(),
? ? hourWeather.getDay(),
? ? hourWeather.getHour(),
? ? hourWeather.getWindDirection(),
? ? hourWeather.getWindPower(),
? ? hourWeather.getWeather(),
? ? hourWeather.getTemperature()
? ? });
System.out.println(row);
? ? }
? ? }
}else if(a==2){
System.out.print("請輸入城市名稱查詢3天天氣預報:");
String city=in.next();
WeatherUtils weatherUtils =new WeatherUtilsImpl();
? ? List<DayWeather> weatherList=weatherUtils.w3d("0d8abeeafc364b5aaa73b7e52ceb83ba", city);
// ? ? System.out.println(weatherList);
? ? if(weatherList.size()==0){
? ? System.out.println("未查詢到信息");
? ? }else{
? ? for(DayWeather weather:weatherList){
? ? String template="%-2s月%-2s日|氣溫:%s(日)%s(夜)|天氣:%s(日)%s(夜)|風力:%s(日)%s(夜)";
? ? String row =String.format(template, new String[]{
? ? weather.getMonth(),
? ? weather.getDay(),
? ? weather.getDayAirTemperature(),
? ? weather.getNightAirTemperature(),
? ? weather.getDayWeather(),
? ? weather.getNightWeather(),
? ? weather.getDayWindPower(),
? ? weather.getNightWindPower()
? ? });
? ? System.out.println(row);
? ? }
? ? }
? ??
}else if(a==3){
System.out.print("請輸入城市名稱查詢7天天氣預報:");
String city=in.next();
WeatherUtils weatherUtils =new WeatherUtilsImpl();
List<DayWeather> weatherList=weatherUtils.w7d("0d8abeeafc364b5aaa73b7e52ceb83ba", city);
// ? ? System.out.println(weatherList);
? ? if(weatherList.size()==0){
? ? System.out.println("未查詢到信息");
? ? }else{
? ? for(DayWeather weather:weatherList){
? ? String template="%-2s月%-2s日|氣溫:%s(日)%s(夜)|天氣:%s(日)%s(夜)|風力:%s(日)%s(夜)";
? ? String row =String.format(template, new String[]{
? ? weather.getMonth(),
? ? weather.getDay(),
? ? weather.getDayAirTemperature(),
? ? weather.getNightAirTemperature(),
? ? weather.getDayWeather(),
? ? weather.getNightWeather(),
? ? weather.getDayWindPower(),
? ? weather.getNightWindPower()
? ? });
? ? System.out.println(row);
? ? }
? ? }
? ??
}
2023-05-04
2022-08-25
已經(jīng) 按老師的教程完成啦,供大家參考
https://github.com/carrieguo/java-weather-forecast.git
2021-05-05
可能是該城市沒有3天7天的數(shù)據(jù),可以直接到API頁面查詢驗證數(shù)據(jù)是否存在。