- 博客(41)
- 资源 (3)
- 收藏
- 关注
原创 谈谈final, finally, finalize的区别
谈谈final, finally, finalize的区别final:修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为final的
2013-07-25 21:46:16 690
原创 接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?
、接口是否可继承接口?答:不可以。接口是要被实现而不是被继承的,加入你用词不当,问接口是否可实现接口,答案仍然是不能,因为接口里面的方法必须全部是抽象方法,接口A实现了接口B,那么A就要重写B的抽象方法,重写了之后,A的性质也就不是接口A了,变成了抽象类A。2、抽象类是否可实现接口?答:可以。正如第一题所说。3、抽象类是否可继承实体类?答:可以。
2013-07-25 21:10:24 1704
原创 JAVA中switch能否用在byte上?能否用在long上?能否用在string上?
不知道你所说的表达式是什么意思。你可以声明一个Long型变量并初始化。如:Long i;或Long i = 10L;至于在switch语句中为什么不能使用Long型变量,java中有这样的规定,switch中的参数只能是离散变量或枚举类型。离散变量包括:byte;int;short;char;枚举类型则需要自己定义,例如public enum{first,second,third}
2013-07-25 20:59:52 4176
原创 Java中equals和==的区别
java中的数据类型,可分为两类:1.基本数据类型,也称原始数据类型。byte,short,char,int,long,float,double,boolean 他们之间的比较,应用双等号(==),比较的是他们的值。2.复合数据类型(类) 当他们用(==)进行比较的时候,比较的是他们在内存中的存放地址,所以,除非是同一个new出来的对象,他们的比较后的结果为true,否则比较后
2013-07-25 20:49:03 654
转载 struts中Action相关
Action配置在struts2框架中每一个Action是一个工作单元。Action负责将一个请求对应到一个Action处理上去,每当一个Action类匹配一个请求的时候,这个Action类就会被Struts2框架调用。 一个Action配置示例:actionname="Logon"class="tutorial.Logon"> resulttype="redir
2013-07-20 16:09:20 588
转载 JQuery 入门24条
JQuery意义:html负责页面内容,css负责页面样式,javascript负责页面行为1,页面加载完成之后,执行代码,可简化2,获取页面制定元素节点,奇数和偶数行匹配::even,:odd3,给控件添加相应的事件代码:load,click,keyup,mouseover,mouseout,change,scroll,resize4,获得节点的CSS属性和内容:val,
2013-07-16 08:43:08 678
转载 Java RMI
Java RMIJava RMI之HelloWorld篇 Java RMI 指的是远程方法调用 (Remote Method Invocation)。它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法。可以用此方法调用的任何对象必须实现该远程接口。 Java RMI不是什么新技术(在Java1.1的时代都有了),但却是是非常重要的底
2013-07-15 17:59:04 647
原创 回溯算法框架
if (最后一层) { if (满足条件) { 打印结果; return; } } 做准备; for (所有情况) { x[k] = 每一
2013-07-14 08:26:57 804
原创 NQueues
package com.zhuyu_deng.test;class NQueues{ int n; int x[]; NQueues(int k) { n = k; x = new int[n]; } void trackback() { explore(0); } void explore(int k) { if (k >= n) {
2013-07-14 07:41:26 766
原创 Hamilton
import java.util.Vector;class Hamilton{ int start; int a[][]; int len; int x[]; // 记录回路 boolean flag; public Hamilton(int[][] a, int n, int start) { this.a = a; this.len = n; this.f
2013-07-13 20:28:49 1154
原创 maxSubArray
private static int maxSubArray(int x[]) { int maxSum = 0; int b = 0; for (int i = 0; i < x.length; ++i) { if (b >= 0) b += x[i]; else b = x[i]; if (b > maxSum) maxSum = b; } retu
2013-07-11 19:24:54 737 2
原创 Algorithm to find square root of an algorithm
Algorithm to find square root of an algorithm
2013-07-11 11:32:23 691
原创 BinaryHeap
class BinaryHeap>{ private T[] array; private int currentSize; private static final int DEFAULT_CAPACITY = 10; BinaryHeap() { this(DEFAULT_CAPACITY); } BinaryHeap(int size) { currentSiz
2013-07-10 21:22:18 1201
原创 Get nth Max number in an array of unsorted integers.
In an array of unsorted integers (you may assume the array may contain +ve, -ve and 0s), write a functionint returnNthMax(int[] arr, int n) which will return the nth Max number. For e.g. if th
2013-07-10 15:20:52 1012
原创 mostFrequentSubArray
Given an array of ints, find the most frequent non-empty subarray in it. If there are more than one such sub-arrays return the longest one/s.Note: Two subarrays are equal if they contain identical e
2013-07-10 12:24:47 635
原创 打印旋转矩阵
package com.zhuyu_deng.test;import java.util.Stack;public class Test{ private static void printRotMatrix(int a[][]) { int n = a.length; for (int i = 0; i < n / 2; ++i) { int fir = i;
2013-07-10 09:03:56 958
原创 矩阵相关
Given a screen with all pixels having one of two colors. Now I will click on a random pixel.Then that pixel & all the adjacent pixels with same color should change the color to the second color.
2013-07-09 22:57:24 863
原创 矩阵最优路径
Given an NxM (N rows and M columns) integer matrix with non-negative values (0..MAX_INT inclusive). What is the maximum sum from going top left (0, 0) to bottom right (N-1, M-1) ? The condition is tha
2013-07-09 17:27:06 1296
原创 maxSubMatrix
private static int maxSubMatrix(int[][] a) { int maxSum = 0; int m = a.length; int n = a[0].length; int b[] = new int[a[0].length]; for (int i = 0; i < m; ++i) { for (int k = 0; k < n;
2013-07-09 16:20:06 724
原创 given two unordered list find the greatest common integer
given two unordered list find the greatest common integer.package com.zhuyu_deng.test;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;public
2013-07-09 11:22:13 921
原创 数组相关问题
Given a list of integers, find out the biggest interval that has all its members in the given list. e.g. given list 1, 7, 4, 6, 3, 10, 2 then answer would be [1, 4]. Develop algorithm and write code f
2013-07-09 09:22:19 632
原创 LIS
Code to find the Longest Increasing Subsequence of an array. Not the length but output the numbers.ANSWER:Method1:package com.zhuyu_deng.test;public class Test{ static int a[] = new int[
2013-07-09 08:01:10 643
原创 找关系在数组中
You given an array:3, 2, 1, 6, 5, 4, 9, 8, 7you have to find a 3 tuple which has property a Answer can have multiple tuples, you have to find any one.In this array, answer will be 3, 6, 9
2013-07-08 16:20:16 608
原创 找差值最小的数
Given - a number (n) and a sorted arrayFind a number in the array having least difference with the given number (n).
2013-07-08 15:05:13 1074
原创 数组问题
ArrayList A, B, C are sorted int arraylists.When A[i] + B[j] = C[k], you need to remove C[k] from ArrayList C.Please implement code with O(N^2). Note that you are not allowed to use additional
2013-07-08 15:02:24 533
原创 求幂
Program to calculate a pow n... public static int power(int n, int x) { if (x == 0) return 1; else if (x == 1) return n; else if (x % 2 == 0) return power(n * n, x / 2); else
2013-07-08 14:48:39 635
原创 one word to another.
Problem: you are given 2 words with equal number of characters. Find an algorithm to go from first word to second word, changing one character at each step, in such a way that each intermediate word e
2013-07-08 14:37:41 648
原创 求两个数组的交集和并集
Given two array of integers write two functions that will return an Union and IntersectionTime efficientBoth time and space efficient implemented
2013-07-08 13:48:49 1103
原创 子集和问题
Given an integer array, find pairs in an array which sum up to a given number.For example: Array{4,5,1,3,2} and required sum=6 then output should be [1,5] and [2,4].此题用回溯法搞定public cl
2013-07-08 13:37:04 763
原创 Check if the given binary tree is BST or not.
Check if the given binary tree is BST or not.
2013-07-08 11:05:34 1131
原创 2.1 链表重复元素(删除)
原文:Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?译文:从一个未排序的链表中移除重复的项进一步地,如果不允许使用临时的缓存,你如何解决这
2013-07-08 10:17:09 734
原创 1.8 判断是否为旋转子串
原文:Assume you have a method isSubstring which checks if one word is asubstring of another. Given two strings, s1 and s2, write code tocheck if s2 is a rotation of s1 using only one call to isSubstri
2013-07-08 09:24:58 765
原创 1.7 处理矩阵元素
原文:Write an algorithm such that if an element in an MxN matrix is 0,its entire row and column is set to 0.译文:写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0.解答:这道题有一个陷阱,如果在遍历矩阵的过程中遇到0就处理,就会出现问题
2013-07-08 08:47:18 731
原创 1.6 矩阵旋转
原文:Given an image represented by an NxN matrix, where each pixel in theimage is 4 bytes, write a method to rotate the image by 90 degrees.Can you do this in place?译文:一张图像表示成NxN的矩阵,图像中每个像素是4个字节,写
2013-07-07 19:21:40 639
原创 1.5 字符串内容替换
原文:Write a method to replace all spaces in a string with ‘%20’.译文:写一个函数,把字符串中所有的空格替换为%20 。public static void main(String args[]) { String s = "i love u."; String
2013-07-07 19:08:36 732
转载 字符串和字符数组之间的转换
字符串类 System.String 提供了一个 void ToCharArray() 方法,该方法可以实现字符串到字符数组的转换。如下例: privatevoid TestStringChars(){ string str = "mytest"; char[] chars = str.ToCharArray(); this.textBox
2013-07-07 18:52:52 2741
原创 1.4 判断两个字符串是否是变位词
原文:Write a method to decide if two strings are anagrams or not.译文:写一个函数判断两个字符串是否是变位词。解答:变位词组成成分相同,所以按照字典顺序排序后,比较。package com.zhuyu_deng.test;import java.util.Arrays;public class
2013-07-07 18:25:21 1661
原创 1.3
原文:Design an algorithm and write code to remove the duplicate charactersin a string without using any additional buffer. NOTE: One or twoadditional variables are fine. An extra copy of the array is
2013-07-07 17:35:07 704
原创 1.1 判断字符串是否由唯一字符组成
原文:Implement an algorithm to determine if a string has all unique characters.What if you can not use additional data structures?译文:实现一个算法来判断一个字符串中的字符是否唯一(即没有重复).不能使用额外的数据结构。(即只使用基本的数据结构)解答
2013-07-07 17:27:43 845
转载 Java并发
Java多线程编程,是并发编程的一种(另一种重要的并发编程是多进程编程)。我们写java程序一般是运行在同一个进程中的,所以可以简单的认为:并发编程=多线程编程,让写操作系统的人去关注多进程编程吧。多线程编程是一个重要的软件基础,不管你的代码是不是多线程,java程序运行在jvm中一定是多线程运行的:运行你的main方法的线程,以及一些后台守护线程,如垃圾收集等。虽然在我们平时的程序中很少直接用到
2013-07-05 18:54:10 737
json以及json依赖的包
2013-12-14
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人