阿里云数据链接
此处需要自行注册阿里云用户(完全免费)
教程链接
如何输入℃
Mac 上输入表示「度」的小圆点有两种方法,
一种是按下「option + K」键,此方法会输出一个小一点的小圆点「˚」
另一种是按下「shift + option + 数字 8」键,此方法会输出一个大一点的圆点「°」
通过这个快捷键,输入摄氏或华氏度的「°C / ˚C / °F / ˚F」标志就变得很简单了。
相关代码:
涉及知识点:List、format格式化输出
package com.study.weather;
import com.imooc.weather.DayWeather;
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.println("请输入你的选择");
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
if (i == 1) {
System.out.print("请输入城市名称查询未来24小时天气预报:");
String city = scanner.next();
WeatherUtils weatherUtils = new WeatherUtilsImpl();
List<HourWeather> weatherList = weatherUtils.w24h("0ef0750173ee4703bc8c9ba1bda5243b", city);
System.out.println(weatherList);
if (weatherList.size() == 0) {
System.out.println("Sorry , 没有查询到相关城市信息");
} else {
for (HourWeather hourWeather : weatherList) {
String template = "%s月%s日%s时|%-3s|%-20s|%-8s|%-4s°C";
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);
}
// System.out.println(weatherList);
}
}
else if(i == 2){
System.out.print("请输入城市名称查询未来3天的天气:");
String city = scanner.next();
WeatherUtils weatherUtils = new WeatherUtilsImpl();
List<DayWeather> weatherList = weatherUtils.w3d("0ef0750173ee4703bc8c9ba1bda5243b",city);
if(weatherList.size()==0) System.out.println("没有查询到相关城市信息");
else{
for(DayWeather weather: weatherList){
String template = "%-2s月%-2s日 | 气温:%s°C(日) %s°C(夜) | 天气:%s(日) %s(夜)|风力:%-8s(日) %-8s(夜)";
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(i == 3){
System.out.print("请输入城市名称查询未来7天的天气:");
String city = scanner.next();
WeatherUtils weatherUtils = new WeatherUtilsImpl();
List<DayWeather> weatherList = weatherUtils.w7d("0ef0750173ee4703bc8c9ba1bda5243b",city);
if(weatherList.size()==0) System.out.println("没有查询到相关城市信息");
else{
for(DayWeather weather: weatherList){
String template = "%-2s月%-2s日 | 气温:%s°C(日) %s°C(夜) | 天气:%s(日) %s(夜)|风力:%-8s(日) %-8s(夜)";
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);
}
}
}
}
}