2014年3月6日
摘要:
1 private static void DFS(Deque in,Stack stack,Deque out) { 2 if(0==in.size()) //输入队列空了 3 { 4 if(0==stack.size()) //栈也空了 输出结果 5 { 6 for(Object obj:out.toArray()) 7 System.out.print(obj); 8 ...
阅读全文
posted @ 2014-03-06 10:15
wf110
阅读(1307)
推荐(0)
2014年3月5日
摘要:
针对递归有两种模式。1.针对原数据进行修改。2.每次都new出数据放入递归。1. 1 private static boolean visited[]=new boolean[num]; 2 private static void DFS(List str,String out,int count) { 3 // if(visited[0]==true&&visited[1]==true&&visited[2]==true&&visited[3]==true) 4 if(count==num) //判断条件...
阅读全文
posted @ 2014-03-05 19:20
wf110
阅读(769)
推荐(0)
摘要:
Java 泛型关键字说明? 通配符类型 表示类型的上界,表示参数化类型的可能是T 或是 T的子类 表示类型下界(Java Core中叫超类型限定),表示参数化类型是此类型的超类型(父类型),直至Objectextends 示例static class Food{}static class Fruit extends Food{}static class Apple extends Fruit{}static class RedApple extends Apple{}List flist = new ArrayList();// complie error:// flist.add(new A
阅读全文
posted @ 2014-03-05 17:01
wf110
阅读(14562)
推荐(4)
摘要:
1 class X 2 { 3 X() 4 { 5 System.out.println("x"); // 6 vir(44); //看到vir会先搜索子类中的vir是否存在,如果不存在再调用父类中的vir 7 } 8 9 public void vir(int x)10 {11 System.out.println("X VIR");12 }13 }14 class Z extends X{15 16 ...
阅读全文
posted @ 2014-03-05 14:26
wf110
阅读(254)
推荐(0)
摘要:
public是所有,在哪都可以访问private是私有,仅在自己类里面可以访问protected是自己包里面可以访问,如果有不同包的类想调用它们,那么这个类必须是定义它们的类的子类。default也是自己包里面可以访问,而且不能被其它包里面的子类访问。调用和直接使用的区别:调用强调新建了对象并且使用其下函数, 而直接使用一般在继承关系中直接用到父类的函数。作用域 当前类 同一package(不管子类还是被新建对象调用) 子孙类(不同包内继承关系的直接使用) 其他package(不同包内不是子孙关系的新建对象调用)public √ √ ...
阅读全文
posted @ 2014-03-05 13:27
wf110
阅读(407)
推荐(0)
摘要:
1 class Father 2 { 3 4 public static String getName() 5 { 6 return "father"; 7 } 8 } 9 10 class Children extends Father11 { 12 public static String getName()13 {14 return "children";15 }16 }17 public class staticTest {18 public static void main(Strin...
阅读全文
posted @ 2014-03-05 11:17
wf110
阅读(161)
推荐(0)
2014年3月4日
摘要:
1 public class XZ 2 { 3 static class b 4 { 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 System.out.println("test"); 8 } 9 }10 }这种写法也是正确的
阅读全文
posted @ 2014-03-04 21:46
wf110
阅读(146)
推荐(0)
摘要:
1 class X 2 { 3 X() 4 { 5 System.out.println("x"); //2 6 } 7 Y y=new Y(); //1 8 } 9 class Y10 {11 12 Y()13 {14 System.out.println("y");15 }16 }17 class Z extends X{18 19 /**20 * @param args21 */22 ...
阅读全文
posted @ 2014-03-04 21:44
wf110
阅读(175)
推荐(0)
2014年3月3日
摘要:
1 for(int i=0;i<10;i++)2 Integer k=new Integer(i);for循环可以不使用{}的,但仅限于执行语句(其中并不包括变量声明语句),由于这段代码在main中重复定义了Integer k,所以编译会出错,只要加上{},让变量声明在块内就可以了,块结束后,块内局部变量会被释放。
阅读全文
posted @ 2014-03-03 21:46
wf110
阅读(258)
推荐(0)
摘要:
1 static void DFS(List list,String str,int n) 2 { 3 System.out.println(str); 4 for (int i=0;i<list.size();i++) 5 { 6 LinkedList link=new LinkedList(list); 7 8 DFS(link,str+link.remove(i),++n); 9 }10 }View Code 用于处理字符串 ...
阅读全文
posted @ 2014-03-03 15:23
wf110
阅读(189)
推荐(0)