java 求任何整数的因子public class T1 { /** * 分析这个数是不是质数 * @param num */ public static boolean isZhishu(int num){ switch (num) { case 1: case 2: case 3: return tru……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3013浏览 2853个赞
java输入半径在控制台用*号绘制圆import java.util.*;public class MathRound{ private int radius; public static void main(String[] args) { int dist; System.out.println("Inpu……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2219浏览 1470个赞
Java获取当前文件的路径String s1=request.getServletPath();//请求的文件的路径(只有项目根目录之后的部分路径)String s2=request.getSession().getServletContext().getRealPath(request.getRequestURI());//请求的文件的绝对路径 ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2824浏览 530个赞
【java】jdom生成xml文件package com.rthb.test;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import org.jdom.Document;import org.j……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1459浏览 2059个赞
java排序算法之桶排序package wzs.sort;import java.util.Arrays;//桶排序 (Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将阵列分到有限数量的桶子里。//每个桶子再个别排序(有可能再使用别的排序算法或是以递回方式继续使用桶排序进行排序)。桶排序是鸽巢排序的一种归纳结果。//当要……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3105浏览 2717个赞
Java解决约瑟夫问题package com.hongqishi;public class JosephQuestion { public static void main(String[] args) { for (int i = 2; i < 11; i++) { findMonitor(initPersons(i),i); ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3275浏览 2487个赞
java判断字符是否属于中文package wzs.arithmetics;// 判断字符是否属于中文public class IsChineseOrEnglish{ // GENERAL_PUNCTUATION 判断中文的“号 // CJK_SYMBOLS_AND_PUNCTUATION 判断中文的。号 // HALFW……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1738浏览 2472个赞
java中获得jdbc结果集元数据转自:http://blog.csdn.net/kobe73er/article/details/8250825import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import com.mysq……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2367浏览 188个赞
java连接oracle数据库代码/** * 单独的java程序连接oracle数据库 * author:JavaAlpha * date :2012-12-3 12:02:44 */import java.sql.*;public class Test {public static void main(String[] args){S……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2412浏览 1141个赞
java分离链式法实现 HashTable JDK中的相应Hashtable中并没有使用LinkedList,而是使用自封装的Entry,显得使其更紧凑,且没有冗余。protected Entry(int hash, K key, V value, Entry<K,V>……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1642浏览 947个赞
java中全角半角字符的相互转换package com.whatycms.common.util;import org.apache.commons.lang.StringUtils;/** * <PRE> * 提供对字符串的全角->半角,半角->全角转换 * */public class BCConvert {……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2881浏览 1613个赞
JAVA中的JSON辅助类/** * 将bean的一组属性,输出成json结果 * * @param bean * @param exclude true为将参数中的属性排除在外,false为将参数中的属性输出成json * @param fieldNames * @return ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2445浏览 2273个赞
java生成缩略图类代码package com.whatycms.common.util;/** * 图片缩小算法,方形区域抽样 */import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imagei……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1744浏览 1152个赞
java 发送邮件范例代码import java.util.Properties;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Session;import javax.mail.Transport;import javax.……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1607浏览 2998个赞
java算法:折半查找(递归算法和非递归算法)来源:http://blog.csdn.net/undoner/article/details/8245870package Ceshi;public class biSearch { /** * @param args */ /* 折半查找--当查找表是有序表时,可采用折半查找; 基本……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3172浏览 1571个赞
java快速排序算法代码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 (……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2132浏览 2098个赞
java堆排序算法代码来源:http://blog.csdn.net/adam_zs/article/details/8262920package com.arithmetic;//堆排序(Heapsort)是指利用堆这种数据结构所设计的一种排序算法。堆是一个近似完全二叉树的结构,//并同时满足堆性质:即子结点的键值或索引总是小于(或者大于)它的父……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1494浏览 2065个赞
java组合排序算法代码来源:http://blog.csdn.net/adam_zs/article/details/8262598package wzs.sort;//用1、2、3、4、5这五个数字,用java写一个main函数,打印出所有不同的排列,如:51234、41235等。 public class Test_wzs012{ ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3167浏览 2721个赞
java二分查找算法代码package wzs.seek;/** * 二分查找 * @author wWX154783 * */public class Test_wzs002{ public static void main(String[] args) { int[] intArray = ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1452浏览 1608个赞
C语言基础:通过指针遍历数组#include <stdio.h>int main(void) { int values[5] = {1, 2, 3, 4, 5}; int counter; int *iptr; iptr = values; for (counter = 0; counter < 5;……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2309浏览 689个赞
C语言基础:多重指针代码演示#include <stdio.h>int what_is_the_value(int ***ptr) { return(***ptr); }int main(void) { int *level_1, **level_2, ***level_3, value = 1001; leve……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2294浏览 980个赞
C语言基础:输出二维数组#include <stdio.h>int main(void) { int row, column; float table[3][5] = {{1.0, 2.0, 3.0, 4.0, 5.0}, {6.0, 7.0, 8.0, 9.0, 10.0},……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2780浏览 284个赞
C语言基础:遍历输出三维数组#include <stdio.h>int main(void) { int row, column, table; float values[2][3][5] = { {{1.0, 2.0, 3.0, 4.0, 5.0}, ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1694浏览 1453个赞
C语言基础:获取命令行传入的参数#include <stdio.h>int main (int argc, char **argv) { while (*argv) printf ("%s\n", *argv++);return 1; }……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2790浏览 1522个赞
将该段代码置于Onclose或自定的响应消息的函数中 TCHAR szPath[MAX_PATH]; // GetModuleFileName(NULL, szPath, MAX_PATH); //获取当前应用程序的全路径 //定义俩变量,具体的请参见msdn STARTUPINFO st……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2657浏览 2059个赞
C语言基础:atexit用法演示代码#include <stdio.h>#include <stdlib.h>void first(void) { printf("First function registered\n"); }void second(void) { printf(&q……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2382浏览 2453个赞
C语言基础:统计用户数组字符数量#include <stdio.h>int main (void) { long character_count = 0; getchar(); while (! feof(stdin)) { getchar(); character_count+……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1388浏览 1026个赞
C语言基础:输出当前日期和时间#include <stdio.h>#include <time.h>int main (void) { time_t current_time; time(¤t_time); // Get the time in seconds; printf(&qu……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1828浏览 2437个赞
单链表反转: 比如原链表为 head->1->2->3->NULL; 反转后:head->3->2->1->NULL; #include <stdio.h>#include <stdlib.h>typedef struct Node{ int data; struct Node *next;}*List;#defi……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1616浏览 1833个赞
C语言基础:延迟执行#include <stdio.h>#include <time.h>int main (void) { time_t current_time; time_t start_time; printf("About to delay 5 seconds\n");……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1517浏览 1261个赞
C语言基础:通过difftime判断时间间隔延迟执行#include <stdio.h>#include <time.h>int main (void) { time_t start_time; time_t current_time; time(&start_time); printf(&……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3239浏览 1289个赞
C语言基础:获得当前日期和时间#include <stdio.h>#include <time.h>int main (void) { struct tm *gm_date; time_t seconds; time(&seconds); gm_date = gmtime(&seco……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1826浏览 877个赞
C语言基础:计算儒略日#include <stdio.h>#include <time.h>int main(void) { time_t seconds; struct tm time_fields; time_fields.tm_mday = 4; time_fields.tm_mon = 7;……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2710浏览 1405个赞
C语言基础:localtime输出当前日期和时间#include <stdio.h>#include <time.h>int main (void) { struct tm *current_date; time_t seconds; time(&seconds); current_date……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3289浏览 1811个赞
C语言基础:mktime用法演示,输出时间差#include <stdio.h>#include <time.h>int main(void) { time_t seconds; struct tm time_fields; time_fields.tm_mday = 4; time_fields.……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1492浏览 1248个赞
C语言基础:设置Timezone#include <stdio.h>#include <stdlib.h>#include <time.h>int main(void) { putenv("TZ=PST8PDT"); tzset(); printf("Curre……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2433浏览 2597个赞
C语言基础:时间转换成字符串 strftime#include <stdio.h>#include <time.h>int main(void) { char buffer[128]; struct tm *datetime; time_t current_time; tzset(); tim……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2925浏览 1992个赞
C语言基础:timezone时区显示#include <stdio.h>#include <time.h>int main(void) { tzset(); printf("Difference between local and GMT is %d hours\n", timez……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2958浏览 2034个赞
C语言去掉字符串首尾的 空格 换行 回车/*去掉字符串首尾的 \x20 \r \n 字符by sincoder*/void clean_string(char *str){ char *start = str - 1; char *end = str; char *p = str; while(*p) { switch(*p)……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2665浏览 759个赞
C语言基础:timezone名字显示#include <stdio.h>#include <time.h>int main(void) { tzset(); printf("Current time zone is %s\n", tzname[0]); if (tzname[1]) ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2687浏览 2983个赞
C语言基础:文件拷贝#include <stdio.h>int main(void) { FILE *input, *output; int letter; if ((input = fopen("\\CONFIG.SYS", "r")) == NULL) printf……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2593浏览 1695个赞
C语言变成:磁盘检测代码片段#include <stdio.h>#include <dos.h>#include <malloc.h>void main(void) { struct fatinfo fat; long sector, total_sectors; void *buffer;……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1829浏览 132个赞
C语言基础:创建文件#include <stdio.h>#include <dos.h>#include <io.h>void main(void) { int handle; if ((handle = creatnew("NEW.DAT", 0)) == -1) ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 1522浏览 361个赞
C语言基础:创建临时文件夹#include <stdio.h>#include <dos.h>#include <io.h>void main(void) { char path[64] = "C:\\TEMP\\"; int handle; if ((handle = ……继续阅读 » 水墨上仙 5年前 (2021-03-14) 2474浏览 2351个赞
在N个元素中查找第K大元素,一般比较简单的方法就是先快速排序,然后直接返回array[N – K]或者利用扫描法,每一次扫描都找到当前数组中最大的元素,这个其实就是部分冒泡排序。前一种算法的时间复杂度是O(NlogN),后一种算法的时间复杂度是K*N。当然,这里我们不打算具体讨论以上两种方案,接下来看看其他方法。 &……继续阅读 » 水墨上仙 5年前 (2021-03-14) 3179浏览 1610个赞