java技術博客

          jsp博客
          數據加載中……

          java中的vector

               摘要: /** *//** *//** *//**  * 我們設計的學生基本類  */ class Student {     private String strName = "";//學生姓名     ...  閱讀全文

          posted @ 2008-11-07 16:02 郭興華 閱讀(350) | 評論 (0)編輯 收藏
          記錄類被實例化的次數

          /*01*/public class classNumberDemo 
          /*02*/{
          /*03*/      public static int objNum=0;
          /*04*/      public classNumberDemo()
          /*05*/      {
          /*06*/          classNumberDemo.objNum++;
          /*07*/      }

          /*08*/      public void show()
          /*09*/      {
          /*10*/          System.out.println("the No."+classNumberDemo.objNum);
          /*11*/      }

          /*12*/      
          /*13*/        public static void main(String args[])
          /*14*/        {
          /*15*/             classNumberDemo p=null;
          /*16*/             p=new classNumberDemo();
          /*17*/             p.show();
          /*18*/             p=new classNumberDemo();
          /*19*/             p.show();
          /*20*/             p=new classNumberDemo();
          /*21*/             p.show();             
          /*22*/      }

          /*23*/}

          posted @ 2008-11-05 22:16 郭興華 閱讀(360) | 評論 (0)編輯 收藏
          java編程小實例

          /**   2005 Aptech Limited
           *     版權所有
           
          */


          /**
           * 該程序測試使用 break 關鍵字來檢測的質數
           * 
          @version 1.0, 2005 年 5 月 22 日
           * 
          @author Michael
           
          */


          public class PrimeNumber {

              
          /** 構造方法*/
              PrimeNumber() 
          {
              }


               
          /**
                * 這是一個 main 方法
                * 
          @param args 傳遞至 main 方法的參數
                
          */


              
          public static void main(String[] args) {

              
          int number = 29;

              
          for (int i = 2; i < number; i++{

                  
          if (number % i == 0{
                  System.out.println(
          "不是質數");
                  
          break;
                  }
           else {
                      System.out.println(
          "它是一個質數");
                      
          break;
                     }

                 }

              }

          }





          /*
           * 2005 Aptech Limited
           * 版權所有
           
          */


          /**
           * 此類將輸出數組中第二個最大的數字
           * 
          @version 1.0, 2005 年 5 月 22 日
           * 
          @author Michael
           
          */


          public class HighestNumber {

              
          /** 構造函數. */
              HighestNumber() 
          {
              }


               
          /**
                * 這是一個 main 方法
                * 
          @param args 傳遞至 main 方法
                
          */


               
          public static void main(String[] args) {


               
          int[] array = {43798};
               
          int greatest = 0;
               
          int secondhighest = 0;

               
          for (int i = 1; i < 5; i++{

                   
          if (greatest < array [i]) {

                   secondhighest 
          = greatest;
                   greatest 
          = array[i];

                   }
           else {

                       
          if (secondhighest < array[i]) {

                           secondhighest 
          = array[i];
                           }

                       }

                   }

                   System.out.println(
          "第二大的數字是: " + secondhighest);

               }

          }

          posted @ 2008-11-04 07:56 郭興華 閱讀(154) | 評論 (0)編輯 收藏
          i++與++i的區別

          public class ppDemo
          {
              
          public static void main(String[] args)
              
          {
              
          int result=0;
              
          int p=2*result++;
              System.out.println(p);
              System.out.println(result);
              result
          =0;
              
          int y=2*++result;
              System.out.println(result);
              System.out.println(y);
              }

          }

          posted @ 2008-11-03 14:37 郭興華 閱讀(125) | 評論 (0)編輯 收藏
          java靜態成員

          /*01*/public class static_demo
          /*02*/{
          /*03*/    public static int i=0;
          /*04*/    public int j=0;
          /*05*/    public void show()
          /*06*/    {
          /*07*/    System.out.println(i);
          /*08*/    System.out.println(j);
          /*09*/    }

          /*10*/}

          /*11*/
          /*12*/class test
          /*13*/{
          /*14*/    public static void main(String args[])
          /*15*/    {
          /*16*/    static_demo obj1=new static_demo();
          /*17*/    obj1.i=100;
          /*18*/        obj1.j=200;
          /*19*/        obj1.show();
          /*20*/        static_demo obj2=new static_demo();
          /*21*/    obj2.show();
          /*22*/    }

          /*23*/}

          posted @ 2008-11-03 14:14 郭興華 閱讀(95) | 評論 (0)編輯 收藏
          java中的靜態代碼段

          /*01*/public class static_block
          /*02*/{
          /*03*/    public String name;
          /*04*/    public String sex;
          /*05*/    public int    age;
          /*06*/  public static_block(String na,String se,int ag)
          /*07*/  {
          /*08*/      name=na;
          /*09*/      sex=se;
          /*10*/      age=ag;
          /*11*/  }

          /*12*/    public void show()
          /*13*/    {
          /*14*/        System.out.println("Name:"+name);
          /*15*/        System.out.println("Sex:"+sex);
          /*16*/        System.out.println("Age:"+age);
          /*17*/    }

          /*18*/    static{
          /*19*/          System.out.println("hello block");
          /*20*/    }

          /*21*/    public static void main(String args[])
          /*22*/    { System.out.println("hello main");
          /*23*/        static_block pObj=new static_block("zhangsan","male",30);
          /*24*/        pObj.show();
          /*25*/    }

          /*26*/}

          posted @ 2008-11-03 08:47 郭興華 閱讀(314) | 評論 (0)編輯 收藏
          ++i與i++

          public class ppDemo{
          public static void main(String[] args)
          {
          int i=0;
          result
          =1+i++;
          System.out.println(i);
          System.out.println(result);
          i
          =0;
          result
          =1+++i;
          System.out.println(i);
          System.out.println(result);
          }

          }

          posted @ 2008-10-31 11:57 郭興華 閱讀(109) | 評論 (0)編輯 收藏
          java代理模式

          package orj.jzkangta.proxydemo02;

          public class ComputerMaker implements SaleComputer {

              
          public void sale(String type) {
                  System.out.println(
          "賣出了一臺"+type+"電腦");

              }


          }



          package orj.jzkangta.proxydemo02;

          import java.lang.reflect.Proxy;

          public class ComputerProxy {
              
          public static SaleComputer getComputerMaker(){
                  ProxyFunction pf
          =new ProxyFunction();
                  
          return (SaleComputer)Proxy.newProxyInstance(ComputerMaker.class.getClassLoader(), ComputerMaker.class.getInterfaces(), pf);
              }

          }





          package orj.jzkangta.proxydemo02;

          import java.lang.reflect.InvocationHandler;
          import java.lang.reflect.Method;

          public class ProxyFunction implements InvocationHandler {
              
          private ComputerMaker cm;
              
              
          public void youHui(){
                  System.out.println(
          "我給你一些優惠。。。");
              }

              
              
          public void giveMouse(){
                  System.out.println(
          "我還要送你一個鼠標。。。 ");
              }

              
          public Object invoke(Object arg0, Method arg1, Object[] arg2)
                      
          throws Throwable {
                  String type
          =(String)arg2[0];
                  
          if(type.equals("聯想")||type.equals("三星")){
                      
          if(cm==null){
                          cm
          =new ComputerMaker();
                          youHui();
                          giveMouse();
                          arg1.invoke(cm, type);
                      }

                  }
          else{
                      System.out.println(
          "我沒有你要的這個牌子的電腦。。。。");
                  }

                  
          return null;
              }


          }

          package orj.jzkangta.proxydemo02;

          public interface SaleComputer {
              
          public void sale(String type);
          }


          package orj.jzkangta.proxydemo02;

          public class Test {

              
              
          public static void main(String[] args) {
                  SaleComputer sc
          =ComputerProxy.getComputerMaker();
                  
          //sc.sale("聯想");
                  
          //sc.sale("三星");
                  sc.sale("Dell");

              }


          }

          posted @ 2008-10-31 07:49 郭興華 閱讀(727) | 評論 (0)編輯 收藏
          java中的多態

          /*01*/public class overdemo1
          /*02*/{
          /*03*/    public static void main(String args[])
          /*04*/    {
          /*05*/    Child c=new Child();
          /*06*/        int iResult=c.add(1,2);
          /*07*/    double dResult=c.add(1.0,2.0);
          /*08*/    System.out.println(iResult);
          /*09*/    System.out.println(dResult);
          /*10*/    }

          /*11*/}

          /*12*/
          /*13*/class Parent
          /*14*/{
          /*15*/   public int add(int a, int b)
          /*16*/   {
          /*17*/       return  a+b;
          /*18*/   }

          /*19*/}

          /*20*/
          /*21*/class Child extends Parent
          /*22*/{
          /*23*/   public double add(double a, double b)
          /*24*/   {
          /*25*/        return a+b;
          /*26*/   }

          /*27*/}

          posted @ 2008-10-30 14:31 郭興華 閱讀(127) | 評論 (0)編輯 收藏
          java方法的重載

          /*01*/public class calculator
          /*02*/{
          /*03*/   public int add(int a, int b)   
          /*04*/   {
          /*05*/        return a+b;
          /*06*/   }

          /*07*/   public double add(double a, double b)
          /*08*/   {
          /*09*/         return a+b;
          /*10*/   }

          /*11*/   public float add(float a, float b)
          /*12*/   {
          /*13*/         return a+b;
          /*14*/   }

          /*15*/   public static void main(String args[])
          /*16*/   {
          /*17*/          calculator cal=new calculator();
          /*18*/          int iResult=cal.add(12,13);
          /*19*/          double dResult=cal.add(12.0,13.0);
          /*20*/          float  fResult=cal.add(12.0f13.0f);
          /*21*/          System.out.println(iResult);
          /*22*/          System.out.println(dResult);
          /*23*/          System.out.println(fResult);
          /*24*/   }

          /*25*/}

          posted @ 2008-10-30 14:23 郭興華 閱讀(80) | 評論 (0)編輯 收藏
          僅列出標題
          共9頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 
          主站蜘蛛池模板: 平顺县| 正蓝旗| 东辽县| 泌阳县| 陕西省| 东兰县| 中牟县| 崇礼县| 江西省| 上饶县| 宜宾市| 清涧县| 青阳县| 包头市| 万州区| 海口市| 镇坪县| 岑巩县| 吉木乃县| 昌黎县| 中宁县| 韶关市| 德化县| 岚皋县| 宜阳县| 彭水| 庆城县| 黄石市| 肇源县| 曲靖市| 溧水县| 石渠县| 巴林右旗| 卓尼县| 容城县| 泗洪县| 云和县| 湄潭县| 于田县| 原平市| 张家港市|