阿里云天气预报查询
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("查询最近天气预报:");
System.out.println("输入1:查询未来24小时天气预报:");
System.out.println("输入2:查询未来3天天气预报");
System.out.println("输入3:查询未来7天天气预报");
System.out.print("请输入您的选择:");
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
System.out.println("用户输入数字:" + i);
if(i==1){
System.out.print("请输入城市名称查询未来24小时天气预报:");
String city = scanner.next();
WeatherUtils weatherUtils = new WeatherUtilsImpl();
List<HourWeather> weatherList = weatherUtils.w24h("50a126968c294b31917b30c417eaea1d",city);
System.out.println(weatherList);
}
}
}
运行结果:
该博客展示了一个Java程序,通过阿里云API实现用户交互,根据用户输入查询未来24小时、3天或7天的天气预报。程序首先提示用户选择查询类型,然后接收城市名,调用WeatherUtilsImpl类获取天气数据并打印。这是一个关于Java编程和API接口应用的例子。
1036

被折叠的 条评论
为什么被折叠?



