lee

          專注技術,關心民生.

          BlogJava 聯系 聚合 管理
            2 Posts :: 0 Stories :: 1 Comments :: 0 Trackbacks

          2005年12月17日 #

          import java.awt.*;
          import java.awt.event.*;
          import java.util.*;
          class wenben extends Frame implements TextListener,ActionListener{
           Button butExit = null;
           TextArea text1 = null; //輸入文件域
           TextArea text2 = null;  //結果輸出的文件域
           public wenben(){
            butExit = new Button();
            add(butExit);
            butExit.addActionListener(this);
             setLayout(null);    //設置界面的格式
            setBounds(35,35,280,250);
            butExit.setBounds(50,200,180,20);
            butExit.setLabel("離開");
             text1 = new TextArea(" ",10,10);
             text1.setBounds(40,50,100,100);
              text2 = new TextArea(" ",10,10);
             text2.setBounds(150,50,100,100);
             add(text1);
             text1.addTextListener(this);
              add(text2);
             text2.setEditable(false);
             text2.addTextListener(this);
              setVisible(true);
          }
            public void actionPerformed(ActionEvent e){
             System.exit(-1);
            }
           public void textValueChanged(TextEvent e)
            {
             double averge = 0; //均值
             double result = 0;  // 和
             int i = 0;
             if(e.getSource()==text1)
              {
               String str = text1.getText();
               StringTokenizer detect = new StringTokenizer(str); //stringtokenizer很用的類,對字符的處理功能強大
               int n = detect.countTokens();
               double[] dou = new double[n]; //也可分配一靜態的數組,這樣不用每次分配空間,但是數組的長度的變化缺少靈活性
               for(i = 0;i<n; i++)
               {
                String temp = detect.nextToken();
                dou[i]=Double.valueOf(temp).doubleValue();
                result = result+dou[i];
               }
               text2.setText(""+result+'\n'+(result/i));
               }
            }
            public static void main(String[] args){
             wenben wb = new wenben();
            } 
          }
          posted @ 2005-12-17 01:17 lee 閱讀(226) | 評論 (0)編輯 收藏

          2005年12月13日 #

          class string{
           static String str = new String("yes");
           string(){}
          }
          public class rtyh {
            public static void main(String[] args){
            string strr = new string();
            String st = new String("yes");
            String str = new String("yes");
            String str1 = "yes";
            String str2 = "yes";
            System.out.println(str1==str2);
            System.out.println(st.equals(str));
            System.out.println(st==str);
            System.out.println(str.equals(strr.str));
            System.out.println(str==strr.str);
             }
           }
          結果為 ture
                         ture
              ture
              ture
                          false
          所以,==用來對引用的判斷,如果是引用的同一個內存單元則相等,否則不相等.equals()用來對字符串內容的逐一判斷.

          posted @ 2005-12-13 13:19 lee 閱讀(849) | 評論 (1)編輯 收藏

          僅列出標題  
          主站蜘蛛池模板: 蓬莱市| 韶关市| 神木县| 青田县| 闻喜县| 瓮安县| 乐昌市| 蓝山县| 静乐县| 三门峡市| 侯马市| 河津市| 龙口市| 通海县| 罗城| 仪征市| 霍州市| 云林县| 社会| 邢台县| 商南县| 肥城市| 阳谷县| 安国市| 和平县| 黑龙江省| 阿克陶县| 历史| 璧山县| 城市| 高要市| 临潭县| 随州市| 巩留县| 兰溪市| 赤壁市| 白河县| 行唐县| 鄂尔多斯市| 深水埗区| 新安县|