「java设计天气」天气预报java程序

博主:adminadmin 2022-11-30 23:59:05 103

今天给各位分享java设计天气的知识,其中也会对天气预报java程序进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java调天气预报

①取出地址中的返回值(getWeatherReader方法)

②解析json格式的字符串

③形成你要展示的天气预报效果

public static String getWeatherReader() {//取得接口字符串

String currentLine = "";

String strReturn = "";

URL url = null;

HttpURLConnection conn = null;

InputStream in = null;

BufferedReader buff = null;

try {

url = new URL("");

System.out.println(url.toURI());

//打开地址链接

conn = (HttpURLConnection)url.openConnection();

conn.connect();

//接收数据

in = conn.getInputStream();

//如有乱码注意编码方式,如:UTF-8

buff = new BufferedReader(new InputStreamReader(in, "gb2312"));

while((currentLine = buff.readLine()) != null) {

strReturn += currentLine;

}

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

in.close();

buff.close();

} catch (IOException e) {

return "8EF0000";

}

}

return strReturn;

}

java编程题,实现一个简单的英中天气转换器

import java.util.Scanner;

public class Weather {

public static String getWeatherInChinese(char c) {

switch (c) {

case 'D':

return "干燥";

case 'M':

return "潮湿";

case 'H':

return "炎热";

case 'R':

return "下雨";

default:

return "输入错误,无法转换";

}

}

public static void main(String[] args) {

boolean tbd = true;

do {

System.out.print("请输入天气情况的第一个英文字母:");

Scanner scanner = new Scanner(System.in);

String input = scanner.next().trim();

if (input.length() != 1) {

System.out.println("输入错误,无法转换!");

} else {

System.out.println(getWeatherInChinese(input.charAt(0)));

}

System.out.print("你想继续吗?(y/n)");

String sta = scanner.next();

tbd = sta.equals("y") ? true : false;

} while (tbd);

System.out.println("退出系统!");

}

}

运行截图:

根据以往天气状况表中数据编写预测以后天气的java程序

用HttpClient调用天气预的url,看一下网上API返回的格式,用JSON封装一下就行了;天气预报一般都是通过webservice来调用的多些。

关于java设计天气和天气预报java程序的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-30,除非注明,否则均为首码项目网原创文章,转载请注明出处。