问答详情
源自:5-3 格式化输出天气预报结果

大神们,输入城市后出现这样的情况该怎么解决啊


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);
                }
            }
        }
    }
}

http://img1.mukewang.com/604f6f680001acce16280182.jpg

http://img.mukewang.com/604f6f680001416011750845.jpg

http://img1.mukewang.com/604f6f6800011c4819201042.jpg

提问者:我爱的人啊在阳光下起舞 2021-03-15 22:31

个回答

  • 鹿晗229
    2021-07-18 22:20:46

    http://img4.mukewang.com/60f438620001516015150782.jpg

    WeatherUtilsImpl类里的appCode一样才行

  • 白袜袜jiojio
    2021-03-17 11:03:56

    看一下购买的api是不是老师那个,如果不完全一样,那就需要修改url