Therangeform of theforloop iterates over a slice or map.package mainimport "fmt"var pow = []int{1, 2, 4, 8, 16, 32, 64, 128}func main() { for i, v ...
分类:
其他好文 时间:
2014-10-27 06:52:09
阅读次数:
183
Variables declared inside anifshort statement are also available inside any of theelseblocks.package main import ( "fmt" "math")func pow(x, n, ...
分类:
其他好文 时间:
2014-10-27 00:23:52
阅读次数:
165
As a simple way to play with functions and loops, implement the square root function using Newton's method.In this case, Newton's method is to approxi...
分类:
其他好文 时间:
2014-10-27 00:18:38
阅读次数:
219
输入一个整数,判断其是否是2^n,若是,输出这个数,若不是,输出和它最接近的为2^n的那个整数。
思路一:用math()函数的pow(2,n)与之比较判断
思路二:如果这个数是2的n次方幂,那可以将这个数先对2取模为0,再对2整除,再对2取模,
一直到这个数最后为2;如果不能这样做,那么这个整数就不是2的n次方幂。...
分类:
其他好文 时间:
2014-10-26 23:05:30
阅读次数:
408
再讲java动态代理前,先来看看代理模式。Proxy类通过组合,对Hello类进行了增强,并对其进行了委托。代理模式代码:public class ProxyPattern { interface IHello{ void say() ; } static class Hello implement...
分类:
编程语言 时间:
2014-10-26 16:54:40
阅读次数:
251
To be an better Gopher, get your hands dirty. Topcoder offered a serials of challenges for learning Golang. In this blog, I tried to implement "Go Lea...
In this challenge, I tried to implement a simple OAuth2 server basing on Simple Web API Server
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the valu...
分类:
编程语言 时间:
2014-10-25 22:57:35
阅读次数:
480
一、Math类
java.lang.Math提供了一系列静态方法用于科学计算;其方法的参数和返回值类型一般为double型。
abs 绝对值
acos,asin,atan,cos,sin,tan 三角函数
sqrt 平方根
pow(double a,doble b) a的b次幂
log 自然对数
exp e为底指数
max(double a,d...
分类:
编程语言 时间:
2014-10-25 18:50:09
阅读次数:
198
本篇主要使用Struts2实现文件的上传与动态下载功能。出于安全考虑,所以,在硬盘上存储上传的文件的时候,统一都重新命名为随机字符串。用数据库存储真实文件名与随机文件名称之间的关联。下面的是实体类?123456789101112131415public class FileBag implement...
分类:
Web程序 时间:
2014-10-25 18:32:42
阅读次数:
347