随笔分类 -  编程之美

各种算法题
关于多态
摘要:1 public class Polymorphism { 2 3 4 /** 5 * @param args 6 */ 7 public static void main(String[] args) { 8 9 Human personA = new man(); 10 // personA.sleep(); 11 // personA.eat(); 12 System.out.println("*********************************... 阅读全文

posted @ 2012-10-28 23:24 chlde2500 阅读(194) 评论(2) 推荐(0)

做过的笔试题
摘要:1.有一数组S[] = {good,apple,fix,king,soft,god,food},要求将这个数组按照首字母分成多个数组,使其成为{apple},{fix,food},{good,god}这种,每一个数组内都是这样有序的。View Code 1 import java.util.ArrayList; 2 3 4 public class strings { 5 6 public ArrayList<ArrayList<String>> get(String[] s){ 7 ArrayList<ArrayList<String>> ar 阅读全文

posted @ 2012-10-28 20:06 chlde2500 阅读(178) 评论(0) 推荐(0)

四个线程,对一个变量进行+1,-1。用Thread和Runnable实现
摘要:1 public class Mtest { 2 3 int j; 4 5 public synchronized void inc(){ 6 j++; 7 System.out.println("plus j is:"+j+"/t thread is:"+Thread.currentThread().getName()); 8 } 9 10 public synchronized void dec(){11 j--;12 System.out.println("menurs ... 阅读全文

posted @ 2012-10-28 16:36 chlde2500 阅读(562) 评论(0) 推荐(0)

二叉树最近公共父节点
摘要:有一个普通二叉树,AB分别为两个子节点,求AB最近的公共父节点。 1 import java.util.ArrayList; 2 import java.util.List; 3 4 5 public class Node { 6 7 Node leftChild; 8 Node rightChild; 9 int data;10 11 public Node(Node leftChild,Node rightChild,int data){12 this.leftChild = leftChild;13 this.... 阅读全文

posted @ 2012-10-26 15:56 chlde2500 阅读(1860) 评论(0) 推荐(0)

24点游戏
摘要:遍历法: 1 public class Calculate { 2 3 final double Threshold = 1E-6; 4 final int CardsNumber = 4; 5 final int ResultValue = 24; 6 double number[] = new double[CardsNumber]; 7 String result[]=new String[CardsNumber]; 8 9 public boolean PointsGame(int n){10 if(n == ... 阅读全文

posted @ 2012-10-25 16:15 chlde2500 阅读(156) 评论(0) 推荐(0)

导航