摘要: The Constructor Date(String) is Deprecated since of JDK 1.1 you should not use itYou should use java.text.SimpleDateFormat to convert String value to Date. E.g.1private static final SimpleDateFormat sdf = new SimpleDateFormat(”yyyy-MM-dd”);2String birthDate = “1981-12-3 阅读全文
posted @ 2010-11-20 11:22 qiang.xu 阅读(2042) 评论(0) 推荐(0) 编辑
摘要: 每日一题:编写一个函数,不使用算术运算符,实现比较两个数的大小问题描述:编写一个函数f,在函数f中,不能够使用算术运算符,实现比较输入两个整数的功能。思路:1.考虑使用绝对值来实现,但是这中方法其实还是在间接地使用了算术运算符,因为在abs函数中,存在数值的判定。实现代码:int max1_large(int a, int b){ return ( (a + b) + abs(a - b) ) / 2;}int max1_small(int a, int b){ return ( (a + b) - abs(a - b) ) / 2;} 阅读全文
posted @ 2010-11-20 09:54 qiang.xu 阅读(926) 评论(0) 推荐(0) 编辑
摘要: 每日一题:给定n, 求出小于n的所有数中1的位数问题描述:给定整数 n,要求编写函数f,返回[1, n]中所有数中1的位数。例如,如果f输入10的话,函数返回2,其中1中含有一个1,10中含有一个1.思路:这里首先想到的是对于给定一个整数 i,如果分解出i的各个数位。这个算法是比较简单的,取模10,然后除10即可。实现的代码如下:// 这个函数直接输入的顺序和原来的数字// 相反的,下面使用递归的形式正序输出void integer2Bit(int i){ while(i > 0) { printf("%d", i % 10); i = i / 阅读全文
posted @ 2010-11-20 09:04 qiang.xu 阅读(577) 评论(0) 推荐(0) 编辑