摘要: public class KNNNode { private int index;// 元祖标号 private double distance;// 与测试元祖的距离 private String c;// 所属类别 public KNNNode(int index, double distance, String c) { super(); this.index = index; this.distance = distance; this.c = c; } public int getIndex(... 阅读全文
posted @ 2013-09-08 21:40 ilxx1988 阅读(1338) 评论(0) 推荐(0) 编辑
摘要: package Entropy;import java.util.Scanner;public class Entropy { public static double Entropy(String str) { double H = 0.0; int sum = 0; int[] letter = new int[26]; str = str.toUpperCase(); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i... 阅读全文
posted @ 2013-05-31 20:19 ilxx1988 阅读(141) 评论(0) 推荐(0) 编辑
摘要: names=["1","2",["3","4"]]def print_lol(the_list,level): for each_item in the_list: if isinstance(each_item,list): print_lol(each_item) else: for tab_stop in range(level): print("\t",end="") print(each_item)print_lol(names,2)上面的结果:12Tra... 阅读全文
posted @ 2013-03-31 14:08 ilxx1988 阅读(2037) 评论(0) 推荐(0) 编辑
摘要: 使用open()BIF 打开一个磁盘文件,创建一个迭代器从文件中读取数据,一次读取一行数据行。readline() 方法从一个打开的文件读取一行数据。seek()方法可以用来将文件“退回”到起始位置close()方法关闭之前打开的文件split()方法可以将一个字符串分解为一个子串列表Python中不可改变的常量列表为元组(tuple)。一旦将列表数据赋值给一个元组,就不能再改变。元组是不可以改变的。数据不符合期望的格式时会出现ValueError。数据无法正常访问时候会出现IOError(例如,可能你的数据文件已经被移走或者重命名)help()BIF允许你在IDLE shell中访问pyth 阅读全文
posted @ 2013-03-29 20:39 ilxx1988 阅读(316) 评论(0) 推荐(0) 编辑
摘要: 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?public class Ex10{public static void main(String[]args){double s=0;double t=100;for(int i=1;i<=10;i++){s+=t;t=t/2;}System.out.println(s);System.out.println(t);}} 阅读全文
posted @ 2013-03-21 15:10 ilxx1988 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 猴子吃桃问题:猴子吃桃子问题:猴子第一天摘下N个桃子,当时就吃了一半,还不过瘾,就又吃了一个。第二天又将剩下的桃子吃掉一半,又多吃了一个。以后每天都吃前一天剩下的一半零一个。到第10天在想吃的时候就剩一个桃子了,求第一天共摘下来多少个桃子?publicclass MonkeyEatsPeach{ publicstaticvoid main(String[] args){ int initialNum=1; System.out.println(initialNum); for(int i=1;i<10;i++){ initialNum=(initialNum+1)*2; System.o 阅读全文
posted @ 2013-03-21 14:48 ilxx1988 阅读(143) 评论(0) 推荐(0) 编辑
摘要: /** * 二元数组的构建 * @author Administrator * */public class TwoArray {public static void main(String[] args){ int array[][]=new int[5][6]; int n=1; for(int i=0;i<array.length;i++){ for(int j=0;j<array[i].length;j++){ array[i][j]=n++; } } for(int i=0;i<array.len... 阅读全文
posted @ 2013-03-08 15:56 ilxx1988 阅读(359) 评论(0) 推荐(0) 编辑
摘要: 1.n有n个台阶,一次只能迈一个台阶或者两个台阶,问有多少种迈台阶的方法?public int fab(int n){ if(n==0||n==1){ return 1; } return fab(n-1)+fab(n-2);}2.n利用四种方式求一个数的阶乘/** * 迭代法 */public int factorialIteration(int m){ int fact=1; for(int i=2;i<=m;i++){ fact*=i; } return fact;}/** * 下降递归策略 * */ publ... 阅读全文
posted @ 2013-03-08 13:24 ilxx1988 阅读(176) 评论(3) 推荐(0) 编辑
摘要: 定义 通常我们所说的动态语言、静态语言指 动态类型语言(Dynamically Typed Language)和 静态类型语言Statically Typed Language)。 还有一个 Dynamic Programming Language (动态编程语言),静态编程语言。动态类型语言:在运行期间检查数据的类型的语言。用这类语言编程,不会给变量指定类型,而是在附值时得到数据类型。如:Python和ruby就是典型动 态类型语言。很多脚本语言vbscrīpt,javascrīpt也是这类语言。看下面javascrīpt代码:function add(a,b){ return a+b; . 阅读全文
posted @ 2013-03-07 23:36 ilxx1988 阅读(228) 评论(0) 推荐(0) 编辑
摘要: def print_lol(the_list): for each_item in the_list: if isinstance(each_item,list): print_lol(each_item) else: print(each_item)movies=["the boy","the life of Brain",["we",["sers"],"Byes"]]movies.append("python");movies.insert(1,"yyy&quo 阅读全文
posted @ 2013-03-04 14:30 ilxx1988 阅读(349) 评论(0) 推荐(0) 编辑