java 小题目

来源:互联网 发布:北京盛世光明软件 编辑:程序博客网 时间:2024/05/17 02:51

http://zhidao.baidu.com/question/92601971.html&__bd_tkn__=78ac19643d2898035b07a178e7f033fdcb058cfa8078338d51fed8133ea5c69d362ad36bb4bcda3b39bb3949f6bbe47087ac3af56e60b1f4e7eb6015715efb329c6eaef940491fc7006f3408d743cc7b4e0298027c28bd8aa238327a72593621c4127b3a3dbda9a2ef09eabbc9db810fc83d27f74e

http://download.csdn.net/detail/fang2113/1378811

http://topic.csdn.net/u/20110827/01/67c19a14-0708-45c3-a4e5-845f2e5ccd5a.html

Java代码

  1. // 日期转化为大小写
  2. public static String dataToUpper(String dateStr) {  
  3.         String res="";  
  4.         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");  
  5.         Date date = null;  
  6. try {  
  7.             date = df.parse(dateStr);  
  8.         } catch (Exception e) {  
  9. // 日期型字符串格式错误
  10. System.out.println("日期型字符串格式错误");  
  11.         }  
  12. if(date!=null){  
  13.             Calendar ca = Calendar.getInstance();  
  14.             ca.setTime(date);  
  15. int year = ca.get(Calendar.YEAR);  
  16. int month = ca.get(Calendar.MONTH) +1;  
  17. int day = ca.get(Calendar.DAY_OF_MONTH);  
  18.             res=numToUpper(year) + "年" + monthToUppder(month) +"月"+dayToUppder(day) + "日";  
  19.         }  
  20. return res;  
  21.     }  
  22. // 将数字转化为大写
  23. public static String numToUpper(int num) {  
  24. // String u[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
  25.         String u[] = { "〇", "一", "二","三", "四","五", "六","七", "八","九" };  
  26. char[] str = String.valueOf(num).toCharArray();  
  27.         String rstr = "";  
  28. for (int i =0; i < str.length; i++) {  
  29.             rstr = rstr + u[Integer.parseInt(str[i] + "")];  
  30.         }  
  31. return rstr;  
  32.     }  
  33. // 月转化为大写
  34. public static String monthToUppder(int month) {  
  35. if (month < 10) {  
  36. return numToUpper(month);  
  37.         } else if (month ==10) {  
  38. return "十";  
  39.         } else {  
  40. return "十" + numToUpper(month -10);  
  41.         }  
  42.     }  
  43. // 日转化为大写
  44. public static String dayToUppder(int day) {  
  45. if (day < 20) {  
  46. return monthToUppder(day);  
  47.         } else {  
  48. char[] str = String.valueOf(day).toCharArray();  
  49. if (str[1] =='0') {  
  50. return numToUpper(Integer.parseInt(str[0] +"")) + "十";  
  51.             } else {  
  52. return numToUpper(Integer.parseInt(str[0] +"")) + "十"
  53.                         + numToUpper(Integer.parseInt(str[1] +""));  
  54.             }  
  55.         }  
  56.     }