base
共 7 篇文章
日期循环
public static void loopDate() throws Exception { SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); String sBegin = "2011-05-16"; String sEnd = "2011-05-26"; java.util.Date dateBegin = formater.parse(sBegin); java.util.Date dateEnd = formater.parse(sEnd); Calendar ca = Calendar.getInst…
2011-05-26 09:24 · base
java判断字符串是否为boolean
public class MyTest { public static void main(String[] args) throws ParseException, EvalError { String s= "2001>1000&&2001<3000";// 这里你可以自己拼一下字符串 Interpreter bs = new Interpreter(); System.out.println(bs.eval(s)); } } 记得引入:bsh-core-2.0b4.jar包
2011-01-28 16:55 · base
java生成随机字符串
String uuid = UUID.randomUUID().toString(); 主要的用途:上传文件时,数据库中保存用户真是上传的文件,而服务器上保存java生成随机字 符串 + 用户上传文件的扩展名,没有扩展名就保存java生成随机字符串加用户上传的名称即 可。
2009-03-30 23:00 · base
单例模式的回顾
实现单例模式的写法有很多种,下面列出单例的几种常用的写法,在写单例的代码前,回 顾下几个方面内容。 1:单例的作用:保证应用程序中,一个(class)类只有一个实例对象。 2:单例的条件: 构造函数是私有的 有一个private static 该类型的实例变量 通过一个public static 的getInstance的方法,获取它的引用。继而调用其中的方法 方式一: public class Singleton { //构造函数声明为private 表示只供内部调用 private Singleton(){}; private static Singleton instance = ne…
2009-03-16 22:57 · base
金额转换
public class ConvertRMB{ private static final char DATA = new char { '零', '壹', '贰', '叁', '肆','伍', '陆', '柒', '捌', '玖' }; private static final char UNITS = new char { '元', '拾', '佰', '仟', '万','拾', '佰', '仟', '亿' }; public static void main(String args) { System.out.println(convert(1234)); } public stati…
2009-03-14 20:28 · base
杨辉三角
public static void print() { int a = new int; for (int i = 0; i < 5; i++) { for (int j = 0; j < i + 1; j++) { if (i == 0 || j == 0 || i == j) { a* = 1; } else { a* = a + a; } System.out.print(a*); } System.out.println(); } } 输出为 1 11 121 1331 14641
2009-03-02 11:55 · base
JAVA笔试题
由于朋友去面试遇到“JAVA 输出左右上下对称的图形” 这道题,特记下以便自己遇到时也能做!哈哈! public class PrintSymmetrical { public static void main(String[] args) { for (int i = 0; i <= 3; i++) { for (int j = 0; j <= 2 - i; j++) { System.out.print(" "); } for (int k = 0; k <= 2 * i; k++) { System.out.print("*"); } System.out.println(""); }…
2009-03-02 11:10 · base