?? 將文本轉化位數字并排序.java
字號:
/* * 將文本轉化位數字并排序.java * * Created on 2004年9月22日, 下午6:25 *//** * * @author litertiger */import java.util.*;import java.io.*;import java.awt.*;import java.awt.event.*;public class 將文本轉化位數字并排序 extends java.applet.Applet implements TextListener { TextArea t1,t2; /** Initialization method that will be called after the applet is loaded * into the browser. */ public void init() { t1=new TextArea("",10,30); t2=new TextArea("",10,30); add(t1); add(t2); t2.setEditable(false); t1.addTextListener(this); // TODO start asynchronous download of heavy resources } public void textValueChanged(TextEvent e) { if(e.getSource()==t1); { String s=t1.getText(); double a[]=new double[50]; StringTokenizer fenxi=new StringTokenizer(s,",'\n'"); //以回車 空格 和逗號作為分隔符 int n=fenxi.countTokens(); for(int i=0;i<=n-1;i++) { String temp=fenxi.nextToken(); //從文本區讀取一個數據 a[i]=Double.valueOf(temp).doubleValue(); } //從小到大排序 for(int i=0;i<n;i++) { for(int j=i+1;j<=n-1;j++) { if(a[j]<=a[i]) {double t=a[j]; a[j]=a[i]; a[i]=t;} } } t2.setText(null); //刷新顯示 for(int i=0;i<n;i++) { t2.append(""+a[i]+","); } } } // TODO overwrite start(), stop() and destroy() methods}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -