摘要: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("*********************************...
阅读全文
摘要: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
阅读全文
摘要: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 ...
阅读全文
摘要:有一个普通二叉树,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....
阅读全文
摘要:1.关于类型初始化对于类的成员变量,编译系统会自动赋予初值,但必须先定义才能使用,可以不必初始化类的成员数据类型的默认值是:boolean:false byte:0 short:0 char:'\u0000' int:'0' float:0.0F double:0.0 object:null但局部变量,不但要先定义,而且还必须要初始化,否则会报错。******************************************************************************************2.传值与传引用java中8种基本数据
阅读全文
摘要:遍历法: 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 == ...
阅读全文
摘要:今天看到一个资料,看到里面讲到int在32位机器中占的是四个字节的内存,我脑海里面感觉这个好像不对,然后在网上查了下资料,发现int类型的数据在32位机器中的确占的内存是4个字节,现在对一些数据结构在内存中所占的字节数总结下。 1: char a: sizeof(a) = 1; 2: int a : sizeof(a) = 4; 3: short a: sizeof(a) = 2; 4: long a: sizeof(a) = 4; 5: double long a: sizeof(a) = 8; 6: float a: sizeof(a) = 8; 7: struct a{ char b;
阅读全文