浏览 1046 次
锁定老帖子 主题:java用stack计算字符串
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2010-01-30
最后修改:2010-02-11
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.Hashtable; import java.util.Iterator; import java.util.Set; public class Run_clsStack { public static void main(String[] args) throws Exception { // File file = new File("f:\\emps.java"); // BufferedReader buffer = new BufferedReader(new FileReader(file)); // while (buffer.ready()) // { // String line = buffer.readLine(); // System.out.println(line); // } String[] cStrings = new String[20]; Hashtable<String, Integer> ht = new Hashtable<String, Integer>(); for (int i = 0; i < 100; i++) { if (i < 100) { Count cls = new Count(); Input_ detail = new Input_(); clsStack_ cls1 = new clsStack_(); String str = detail.InputString_(); String var = str.split("=")[0].split(" ")[1]; String value1 = str.split("=")[1]; String value = value1.split(";")[0]; System.out.println("Value:" + value); // 取代字母给予值 // Set<String> htt = (Set<String>)ht.keySet(); // System.out.println("size =====================> " + htt.size()); // for (Iterator iterator = htt.iterator(); iterator.hasNext();) // { // String key = (String)iterator.next(); // value = value.replace(key, ht.get(key) + ""); // } cStrings = value.split("\\/|\\*|\\+|\\-"); for (int j = 0; j < cStrings.length; j++) { if (ht.get(cStrings[j]) != null) { value = value.replace(cStrings[j], ht.get(cStrings[j]) + ""); } } // 通过计算得值 double db = cls1.getValue(value); int c = (int)db; ht.put(var, c); System.out.println("值:" + db); System.out.println("---------------------------------"); } else { break; } } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |