private static String beforeBh; private static String beforeNum; public static String codeGenerate() { Date now = new Date(); String behind = now.getTime()+""; if(beforeBh==null) { beforeBh = behind;
public class PropsUtil { private static final Logger logger = LoggerFactory.getLogger(PropsUtil.class); private Properties props = null; public PropsUtil(String propsPath) { this(propsPath, Const.DEFA
约瑟夫问题 这是17世纪的法国数学家加斯帕在《数目的游戏问题》中讲的一个故事:15个教徒和15 个非教徒在深海上遇险,必须将一半的人投入海中,其余的人才能幸免于难,于是想了一个办法:30个人围成一圆圈,从第一个人开始依次报数,数到第九个人就将他扔入大海。该人后面的人从1开始重新报数,如此循环进行直到仅余15个人为止。问怎样排法,才能使每次投入大海的都是非教徒。 思路 1. 先建立一个类,有 id
private void output(HttpServletResponse response, String filePathAndFileName, String mimeType) throws IOException { File file = new File(filePathAndFileName); // set response headers response.setConte
通过移除空行和注释来压缩 JavaScript 代码 /** * This file is part of the Echo Web Application Framework (hereinafter \"Echo\"). * Copyright (C) 2002-2009 NextApp, Inc. * * Compresses a String containing JavaScript b
package Mypackage; public class QuickSort { public static void main(String[] args) { int[] arr = { 2, 5, 4, 3, 7, 0, 9, 1, 6, 8 }; quickSort(arr, 2, 7); for (int i = 0; i < arr.length; i++) System.out
public class FormatTools { /** * 判断邮箱 * * @param email * @return */ public static boolean isEmail(String email) { String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([
/** 操作数据库 */ public class BackupDb { public String backup() throws IOException{ String user = "root"; //数据库的用户名 String password = "admin";//数据库的密码 String database = "hrtweb";//要备份的数据库名 Date date = new
private double[] divide(double totalMoney,int num,double minMoney){ double[] each = new double[num]; for(int i=0;i<num-1;i++){ //计算最大安全值,保证不会超出 。如果安全值越大,价格波动越大 .建议是平均值 double maxSafeMoney = (totalMone
public class T { /** * 随机生成 num位数字字符数组 * * @param num * @return */ public static char[] generateRandomArray(int num) { String chars = "0123456789"; char[] rands = new char[num]; for (int i = 0; i < nu
public class JoinTest { public static void main(String[] args) { // TODO Auto-generated method stub Thread t1 = new ThreadA();//利用多态实例化一个A线程 Thread t2 = new ThreadB(t1);//利用多态实例化一个B线程 t1.start(); t2.s
public class GenerateSampleData { public void select() { String sql=""; Connection con = null; CallableStatement callAble=null; try{ Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://lo
package com.page; public class PageUtil { // 每页显示的条数 private int pageSize; // 总共的条数 private int recordCount; // 当前页面 private int currentPage; public PageUtil(int pageSize, int recordCount, int current
代码演示: //数据库中去的日期 Date s = list.get(0).getSdate(); System.out.println(s);// Tue Apr 28 00:00:00 CST 2015 //手动new Date d = new Date(); System.out.println(d);// Tue Apr 28 20:53:15 CST 2015 System.out.pr
冒泡排序 public class BubbleSort { public static int[] bubbleSort(int[] array) { if (array == null) { return null; } for (int i = 0; i < array.length; i++) { for (int j = i + 1; j < array.length; j++) { i
URL url = new URL(Config.local + "/excel/" + name); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); // 设置请求信息 httpConnection.setRequestProperty("GET", "/down.zip HTTP/1.1"
System.setProperty("http.maxRedirects", "50"); System.getProperties().setProperty("proxySet", "true"); // 如果不设置,只要代理IP和代理端口正确,此项不设置也可以 System.getProperties().setProperty("http.proxyHost",“代理ip地址”); Sy
/** * 默认GB18030 */ public static final String detectCharset(byte[] byteArray){ // 建立InputStream ByteArrayInputStream bais = new ByteArrayInputStream(byteArray); // 默认编码 String utf8 = "UTF-8"; String c
获取本地服务器IP经常会出现127.0.0.1,0:0:0:0:0:0:0:1,fe80:0:0:0:960:74bd:e1a0:e5b9%11 这些情况,以下代码可解决此问题 public static void main(String[] args) { try { Enumeration<NetworkInterface> enumeration = NetworkInterface .ge
MongoDB的数据 ================================ { "_id" : ObjectId("54d3509f30c0ed0f308ed1ef"), "cust_id" : "A123", "amount" : 500.0, "status" : "A" } { "_id" : ObjectId("54d350a830c0ed0f308ed1f0"), "cust