我爱的人啊在阳光下起舞
2021-03-15 22:31
package TianQiYuBao; import com.imooc.weather.HourWeather; import com.imooc.weather.WeatherUtils; import com.imooc.weather.impl.WeatherUtilsImpl; import java.util.List; import java.util.Scanner; public class Application { public static void main(String[] args) { System.out.println("输入想要查询的天气:24小时。:三天。:七天。"); System.out.print("输入你的选择:"); Scanner scanner = new Scanner(System.in); int i = scanner.nextInt(); System.out.println("你输入的是:"+i); if (i == 24){ System.out.print("输入要查询的城市名称:"); String city = scanner.next(); WeatherUtils weatherUtils = new WeatherUtilsImpl(); List<HourWeather> weatherList = weatherUtils.w24h("553d41feff124ac6a2fce95fc0810eba",city); //System.out.println(weatherList); if (weatherList.size() == 0){ System.out.println("抱歉,未查询到您想要的数据。"); }else{ for (HourWeather hourWeather : weatherList){ String template = "%s月%s日%s时|%s|%s|%s|%s@"; 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); } } } } }
WeatherUtilsImpl类里的appCode一样才行
看一下购买的api是不是老师那个,如果不完全一样,那就需要修改url
Java入门第二季 升级版
530649 学习 · 6091 问题
相似问题