08 2012 档案

摘要://递归实现获取对应目录下的子目录及文件 1 package com.lixl.test; 2 3 import java.io.*; 4 5 public class FileList { 6 7 public static void main(String[] args){ 8 9 File f = new File("D:/eclipse");10 int level = 0;11 12 System.out.println(f.getName());13 level+... 阅读全文
posted @ 2012-08-02 22:57 cnlixl 阅读(274) 评论(0) 推荐(0)
摘要:errno(需include errno.h),当API调用出错时保留最后一次出错信息,在unix系统下作为一种常用的调试手段。但是errno是一个数字,代表的具体含义还要到errno.h中去阅读宏定义,而每次查阅是一件很繁琐的事情。有下面几种方法可以方便的得到错误信息(1)void perror(const char *s)函数说明perror ( )用来将上一个函数发生错误的原因输出到标准错误(stderr),参数s 所指的字符串会先打印出,后面再加上错误原因 字符串。此错误原因依照全局变量 errno 的值来决定要输出的字符串。(2) char *strerror(int errno)将 阅读全文
posted @ 2012-08-02 22:02 cnlixl 阅读(168) 评论(0) 推荐(0)
摘要:以下代码为什么会出错呢?不理解啊,只能研究研究了。 1 void main(){ 2 unsigned long i =0,*p,*p1; 3 p = (unsigned long *)malloc(10000); 4 p1 = p; 5 6 for(i = 0;i < 9999;i++){ 7 *p1 = 0x100; 8 p1++; 9 }10 free(p);11 }VC运行时,貌似是进入了死循环。难道是类型不兼容造成了什么问题?待解。。。 阅读全文
posted @ 2012-08-01 08:09 cnlixl 阅读(135) 评论(2) 推荐(0)
摘要:求斐波纳契数列第n个数的两种实现方法。 1 public class TestFibo { 2 3 public static void main(String[] args){ 4 System.out.println(f(7)); 5 System.out.println(fn(7)); 6 } 7 8 //递归实现 9 public static long f(int index){10 11 if(index<1){12 System.out.p... 阅读全文
posted @ 2012-08-01 07:55 cnlixl 阅读(149) 评论(0) 推荐(0)
摘要:用冒泡算法实现对日期的排序 1 //日期类,包含年月日的信息。重写toString 2 //方法,输出年月日信息。 3 public class Date { 4 5 public int year ,month,day; 6 7 public Date(int year,int month,int day){ 8 this.year = year; 9 this.month = month;10 this.day = day;11 }12 13 public String toString()... 阅读全文
posted @ 2012-08-01 07:47 cnlixl 阅读(150) 评论(0) 推荐(0)