免费试用网站制作设计说明书范文
news/
2025/10/9 0:10:49/
文章来源:
免费试用网站制作,设计说明书范文,西安大型网站建设公司排名,网站搜索建设用来查询农历年的代码#xff0c;可能比较粗糙#xff0c;希望不要太打击偶#xff0c;哈哈。一#xff0c;Console.java[用来获取控制台的输入]/*#()Console.java 20:40:25 2/2/2006控制台消息输入/输出。*/import java.io.*;import java.text.SimpleDateFormat;import ja…用来查询农历年的代码可能比较粗糙希望不要太打击偶哈哈。一Console.java[用来获取控制台的输入]/*#()Console.java 20:40:25 2/2/2006控制台消息输入/输出。*/import java.io.*;import java.text.SimpleDateFormat;import java.util.Calendar;public final class Console {public Console() {}private static SimpleDateFormat style new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);/*** 根据提示返回用户的输入** param s String 控制台输入提示* return String 返回用户的控制台输入*/public String read(String m) {String s null;System.out.println(m);try {BufferedReader in new BufferedReader(new InputStreamReader(System.in));s in.readLine();} catch (IOException ex) {printError(this.getClass().getName(), read(String s), ex.getMessage());}return s;}/*** 根据提示返回用户的输入** param s String 控制台输入提示* return String 返回用户的控制台输入*/public int readInt(String s) {int x;try {x Integer.parseInt(this.read(s));} catch (NumberFormatException ex) {x 0;printError(this.getClass().getName(), readInt(String s), ex.getMessage());}return x;}/*** 根据提示返回用户的输入** param s String 控制台输入提示* return String 返回用户的控制台输入*/public Double readDouble(String s) {double x;try {x Double.parseDouble(this.read(s));} catch (NumberFormatException ex) {x 0;printError(this.getClass().getName(), readInt(String s), ex.getMessage());}return x;}/*** 打印错误消息** param c String 类名* param m String 方法名* param e String 错误信息*/public void printError(String c, String m, String e) {System.out.println(style.format(Calendar.getInstance().getTime()) 调用 c . m 方法时发生错误 e 。);}/*** main(String[] args)方法*/public static void main(String[] args) {Console c new Console();System.out.println(c.readDouble(请输入Double类型的数字……));}}二Chinese.java[计算农历年的代码]/*#()Chinese.java 21:56:25 2/2/2006中国农历。干支纪年始于公元四年即第一个甲子年故甲、子位于数组中的第四位。*/import java.text.SimpleDateFormat;import java.util.Calendar;public final class Chinese {public Chinese() {}private Console c new Console();/*天干数组*/private String[] s {庚, 辛, 壬, 癸, 甲, 乙, 丙, 丁, 戊, 己};/*地支数组*/private String[] t {申, 酉, 戌, 亥, 子, 丑, 寅, 卯, 辰, 巳, 午, 未};/*十二生肖*/private String[] g {猴, 鸡, 狗, 猪, 鼠, 牛, 虎, 兔, 龙, 蛇, 马, 羊};private String again null;/*** 根据用户的输入确定继续查询或退出运行**/public void chinese() {if (this.chineseera()) {String s c.read(提示按回车键退出重新查询请输入新的年数后按回车键。);if (s ! null !s.trim().equals()) {again s;this.chinese();} else {System.exit(0);}}}/*** 根据用户的输入查询农历年和生肖属相如果没有用户输入则按当前年度开始查询**/private boolean chineseera() {boolean b false;String year null;if (again null) {year c.read(请输入准备查询农历年的年数完成后按回车键。);if (year null || year.equals()) {SimpleDateFormat style new SimpleDateFormat(yyyy);year style.format(Calendar.getInstance().getTime());}} else {year again;}int i this.last(year);if (i ! -1) {int y this.cathay(year);System.out.println(year 年是农历 s[i] t[y] 年十二生肖中属 g[y] 。);b true;}return b;}/*** 取得字符串的最后一位字符并转换成数字型变量* 取得天干时的算法主要是用最后一位数字对应天干数组中的数位字符** param s String 用户输入的年数* return int 返回转换后的最后一位数字如果发生错误则返回-1*/private int last(String s) {int y 0;if (s ! null) {try {s s.substring(s.length()-1, s.length());y Integer.parseInt(s);} catch (NumberFormatException ex) {y -1;c.printError(this.getClass().getName(), last(String s), ex.getMessage());}}return y;}/*** 取得字符串除以十二以后的余数* 取得地支时的算法主要是用除以十二以后的余数对应地支数组中的数位字符* 十二生肖的算法也与此相同** param s String 用户输入的年数* return int 返回除以十二以后的余数*/private int cathay(String s) {int y 0;try {y Integer.parseInt(s);y % 12;} catch (NumberFormatException ex) {c.printError(this.getClass().getName(), cathay(String s), ex.getMessage());}return y;}/*** main(String[] args)方法*/public static void main(String[] args) {Chinese cathay new Chinese();cathay.chinese();}}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/932081.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!