沒發現大括號那有問題呢,請大家幫忙指出來
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: 需要'}'
2021-12-06
我發現問題了,錯誤的把每個元素的get方法后面用了分號