java编程题
1个回答
关注
展开全部
亲,您好java编程题如下:1、编写一个Java程序,用if-else语句判断某年份是否为闰年。(分支)// Programme Name LeapYear.javapublic class LeapYear{public static void main(String args[){int year= 2010; .if(args.length!=0)year=Integer.parseInt(args[0]);if(year%4==0 & & year% 100!=0)l(year%400==0))System.out.println(year+"年是闰年。");elseSystem.out.println(year+"年不是闰年。");}/if-else语句2、编写一个Java程序在屏幕上输出1! +2! +3! ...+10!.. 的和。(循环)// programme name ForTest.javapublic class ForTest {public static void main( String args[] ) {int ij,mul,sum=0;for(i=1;i<= 10;i++) {mul=1;for(j=1j<= i;j++) {mul=mul*j;sum=sum+mul;System.out.println(“1! +2! +3! +....+!. =”+sum);}}
咨询记录 · 回答于2023-03-05
java编程题
亲,您好java编程题如下:1、编写一个Java程序,用if-else语句判断某年份是否为闰年。(分支)// Programme Name LeapYear.javapublic class LeapYear{public static void main(String args[){int year= 2010; .if(args.length!=0)year=Integer.parseInt(args[0]);if(year%4==0 & & year% 100!=0)l(year%400==0))System.out.println(year+"年是闰年。");elseSystem.out.println(year+"年不是闰年。");}/if-else语句2、编写一个Java程序在屏幕上输出1! +2! +3! ...+10!.. 的和。(循环)// programme name ForTest.javapublic class ForTest {public static void main( String args[] ) {int ij,mul,sum=0;for(i=1;i<= 10;i++) {mul=1;for(j=1j<= i;j++) {mul=mul*j;sum=sum+mul;System.out.println(“1! +2! +3! +....+!. =”+sum);}}
邮区编号查询题。要求:输入省份,列出所有城市的区号和邮编;输入城市,查询区号和邮编及所在的省份
补充资料:更多的java编程题网址:https://wenku.baidu.com/view/8df724f91fd9ad51f01dc281e53a580217fc5031.html?fr=aladdin664466&ind=1&_wkts_=1677995037709&bdQuery=java%E7%BC%96%E7%A8%8B%E9%A2%98您可以进去里面下载题目练习。
亲您好,邮区编号查询题。java编程如下:1| package 邮编查询11;“录后复制3| import java. io . BufferedReader;import java . io . DataOutputStream;import java. io. IOException;import java. io . InputStream;7| import java. io. InputStreamReader;3 import java. io.UnsupportedEncodingException;) import java . net . HttpURLConnection;10import java . net.URL;11import java . net. URLEncoder;12import java. util .HashMap;13import java . util.Map;14 import java.util. Scanner; 1516import net. sf. json. JSONArray;17import net. sf. json. JSONObject;1819| public class Post_ check {20public static final String DEF_ CHATSET = "UTF-8";21public static final int DEF_ CONN_ TIMEOUT = 30000 ;22public static final int DEF_ READ_ TIMEOUT = 30000;23public static String userAgent = "Mozilla/5.0 (Nindows NT 6.1) AppleWebKit/537.36 (KHTMI24public static final String APPKEY="** ”';//需要替换25public static void request(String post){26String result =null;27String url ="http://v. juhe . cn/ postcode/query"
polic statc void reuest(trirse posty(Stringresult =null;string url tp:/che.c/po.code/query" ;/请求接口地址Map params “new Hasha)a);/请求参数params .put("postcode". ,ost)/邮编,如:215001params.put("key" ,APKEY);try {result =net(url,params, “GET");asoNobject object。ISoNobject.fromobject(result);if(object.gtInt("error-_code" )==0){//解析SoNobject集合得到所需要部分object=o-object.getsoNobject("result");3somry arayobyect.gectSONArray("list");object=array .gegetSoNobject(0); jectgetstring(""province" ));System.out.print(objt.System.out.pxint(object..getString("city" );etString("District"));}else{sSystem. out .printIn((“查询失败,失败详情如下:“);.systomntr.totnofoect.get(""error. code"“")+"+":" toetetereson'));1} catch (Exception e) {e.printStackTrace();}
//将map型转为请求参数型public static String urlencode (Mapdata) {StringBuilder sb = new StringBuilder();for (Map. Entry i : data. entrySet()) {try {sb. append(i. getKey()) . append("=") . append(URLEncoder . encode(i. getValue()+"","I} catch (UnsupportedEncodingException e) {e. printStackTrace();}}return sb. toString();}public static void main(String args[]){System. out. println("请输入想要查询邮编”);Scanner SC=new Scanner(System.in);String post=sc.next();System. out . print("所输入邮编地址为: ");request(post);}
亲,您好,这就是你发的题目的相关编程答案的。