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 阅读(213) | 评论 (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 阅读(839) | 评论 (1)编辑 收藏

仅列出标题