上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 72 下一页
摘要: 换位输出public static void main(String[] args) { Scanner scan = new Scanner(System.in);// 创建扫描器 System.out.println("请输入变量A的值"); long A = scan.nextLong();// 接收第一个变量值 System.out.println("请输入变量B的值"); long B = scan.nextLong();// 接收第二个变量值 System.out.println("A=... 阅读全文
posted @ 2012-05-09 22:07 Java EE 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 二分查找 public static int binarySearch(int[] srcArray, int des) { int low = 0; int high = srcArray.length - 1; while (low <= high) { int middle = (low + high) / 2; if (des == srcArray[middle]) { return middle; } else if (des < srcArray[middle]) { high = middle - 1; } else { ... 阅读全文
posted @ 2012-05-09 22:03 Java EE 阅读(161) 评论(0) 推荐(0) 编辑
摘要: 汉诺塔 private static void move(char x,char y){ System.out.printf("%c-->%c",x,y); System.out.print("\n"); } private static void hanoit(int n,char one,char two,char three){//将n个盘子从第一座借助第二座移到第三座 if(n==1){//如果只有一个盘子 move(one,three); } else{ hanoit(n-1,one,three,two);//将一上的盘子借助三移到二上 阅读全文
posted @ 2012-05-09 21:47 Java EE 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 素数public static void main(String[] args) { Scanner s=new Scanner(System.in); System.out.println("请输入你要判断的数!"); int x=s.nextInt(); int i=2,flage=0; while(flage==0&&i<x){ //对除数进行遍历 if(x%i==0){ //判断是否被整除 flage=1; } else{ i++; } } if(flage==0){ //... 阅读全文
posted @ 2012-05-09 21:43 Java EE 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 水仙花数 public static void main(String[] args) { int a=0,b=0,c=0; System.out.println("水仙花数是:"); for (int i = 100; i < 1000; i++)//遍历所有3位数 { a = i/100;//获取3位数中百位的数 b=i%100/10;//获取3位数中十位的数 c=i%100%10;//获取3位数中个位的数 a = a * a * a; //计算第一位数的立方... 阅读全文
posted @ 2012-05-09 21:42 Java EE 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 斐波那契数列 private static void f(int x){ int f1=1,f2=1,i=3; if(x==1)System.out.print(f1); if(x==2)System.out.print(f1+" "+f2); if(x>=3){ //求位置大于三的数列 System.out.print(f1+" "+f2); while(x>=i){ //求数列 f1=f2+f1; //求两项之和 System.out.print(" "+f1)... 阅读全文
posted @ 2012-05-09 21:39 Java EE 阅读(236) 评论(0) 推荐(0) 编辑
摘要: 韩信点兵 public static void main(String[] args){ int a=0,b=0,c=0,preson; //定义总人数和各种站法的剩余人数 for(preson=0;preson<100;preson++){ a=preson%3; //每排三人剩余人数 b=preson%7; //每排七人的剩余人数 c=preson%5; //每排五人的剩余人数 if(a==1&&b==5&&c==0){ //都符合条件时的人数 Syste... 阅读全文
posted @ 2012-05-09 21:34 Java EE 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 百钱买百鸡 public static void main(String[] args) { int cock,hen,chicken=0; for(cock=0;cock<=19;cock++){ for(hen=0;hen<=33;hen++){ chicken=100-cock-hen; int p; p=chicken%3; if(((5*cock+3*hen+chicken/3)==100)&&(p==0)){ System.out.print(" 可以买公鸡的只数:"+cock); System.out.pri... 阅读全文
posted @ 2012-05-09 21:30 Java EE 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 归并算法 private static void merge(int r[],int r1[],int s,int m,int t){ int i=s,j=m+1,k=s; while(i<=m&&j<=t){ if(r[i]<=r[j]){ r1[k++]=r[i++]; //取r[i]和r[j]中较小者放入r1[k] } else{ r1[k++]=r[j++]; } } if(i<=m){ while(i<=m){ //若第一个子序列处理完,则进行收尾处理 r1[k++]=r[i+... 阅读全文
posted @ 2012-05-09 21:27 Java EE 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 插入排序public static void main(String[] args) { int r[]={49,27,65,97,76,13,38,5,12,56}; //给出原始数的序列 int i,j,temp,k; //定义变量名称 System.out.println("放置初始序列的数组为:");//输出初始序列 for(i=0;i<10;i++){ System.out.print(r[i]+" "); } for(i=1;i<10;i++){... 阅读全文
posted @ 2012-05-09 21:24 Java EE 阅读(120) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 72 下一页