qq_慕慕慕
2021-12-06 16:50
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 scanner = new Scanner(System.in);
int i = scanner.nextInt();
System.out.println("请输入数字" + i);
//进行判断
if(i == 1){
System.out.println("请输入城市名称:");
String city = scanner.next();
//接口weatherutils实例化
WeatherUtils weatherUtils = new WeatherUtilsImpl();
List<HourWeather> list = weatherUtils.w24h("acbfa8f57a4b4b9cbe59d86c38ec6db2",city);
System.out.println(list);
//格式化判断输出
if(list.size() == 0){
System.out.println("没有查询到您输入城市的天气信息");
}else {
//如果list.size()不等于0 则对HourWeather数据进行遍历
for(HourWeather hourWeather:list){
//定义一个格式化模板
String template = "%s月%s日%s时 | %-4s | %-20s | %-8s | %-4s摄氏度 ";
//返回字符串row,代表一行数据
String row = String.format(template,new String[] {
hourWeather.getMonth();
hourWeather.getDay();
hourWeather.getHour();
hourWeather.getWindDirection();
hourWeather.getWindPower();
hourWeather.getWeather();
hourWeather.getTemperature();
});
//将row数据打印输出
System.out.println(row);
}
}
}else if(i == 2){
}
}
}报错信息:
D:\weather\src\com\zhang\weather\Application.java:44:43
java: 需要'}'
我发现问题了,错误的把每个元素的get方法后面用了分号
Java入门第二季
531404 学习 · 6328 问题
相似问题