java eval
½ñÌìһͬѧ×ö¶«Î÷ÒªÓÃÕâ¸ö¶«¶«,¾Í°ïËûдÁËÒ»¸ö,ÏÈת»¯³Éºó׺±í´ïʽ,È»ºóÔÙ
¼ÆËã.µ±È»Ò²¿ÉÒÔÖ±½Ó¼ÆËãÖÐ׺±í´ïʽ,¿¼Âǵ½Òª¶àλÊý,¾ÍûÄÇô×ö.
Ö§³Ö¶àλÊýµÄ´øÀ¨ºÅµÄÕûÊýµÄ¼Ó¼õ³Ë³ý.
Java
´úÂë
package
edu.jlu.fuliang;
import
java
.util.ArrayList;
import
java
.util.List;
import
java
.util.Stack;
public
class
Eval
{
public
int
eval
(String exp){
List<String> list = infixExpToPostExp(exp);//ת»¯³Éºó׺±í´ïʽ
return
doEval(list);
//ÕæÕýÇóÖµ
}
//Óöµ½²Ù×÷·ûѹջ£¬Óöµ½±í´ïʽ´Óºó׺±í´ïʽÖе¯³öÁ½¸öÊý£¬¼ÆËã³ö½á¹û£¬Ñ¹Èë¶ÑÕ»
private
int
doEval(List<String> list) {
Stack<String> stack = new
Stack<String>();
String element;
int
n1,n2,result;
try
{
for
(
int
i =
0
; i < list.size();i++){
element = list.get(i);
if
(isOperator(element)){
n1 = Integer.parseInt(stack.pop());
&nb
Ïà¹ØÎĵµ£º
¡¡ ¡¡¡¡
¡¡¡¡Èí¼þ¿ª·¢Ö®Â·ÊdzäÂú¾£¼¬ÓëÌôս֮·,Ò²ÊdzäÂúÏ£Íû֮·¡£JAVAѧϰҲÊÇÈç´Ë£¬Ã»Óнݾ¶¿É×ß¡£ÃÎÏëÏñ¡¶ÌìÁú°Ë²¿¡·ÖÐÐéÖñÒ»Ñù±»ÎÞÑÂ×Óõ®õ¹à¶¥¶øÇáËÉ»ñµÃÒ»¼××Ó¹¦Á¦£¬ÊǺܲ»ÏÖʵµÄ¡£Ã¿ÌìÑöÌì´ó½Ð"ÌìÉñ°¡£¬Çë´Í¸øÎÒÒ»±¾¿û»¨±¦µä°É"£¬Êâ²»Öª¼´Ê¹Äã»ñµÃÁË¿û»¨±¦µä£¬³ýÁËÊÜ×Ô¹¬ÆäÉíÖ®¿àÍ⣬ÄãÒ²²»Ò»¶¨³ÉµÃÁË"¶«·½² ......
1.ʹÓÃjava.util.PropertiesÀàµÄload()·½·¨
InputStream in = lnew BufferedInputStream(new FileInputStream(name));
¡¡¡¡Properties p = new Properties();
¡¡¡¡p.load(in);
2.ʹÓÃjava.util.ResourceBundleÀàµÄgetBundle()·½·¨¡¡¡¡
ResourceBundle rb = ResourceBundle.getBundle(name, Locale.getDefault ......
×÷Õßͨ¹ýʹÓÃJAVAÖеĶ¯Ì¬´úÀíʵÏÖÊý¾Ý¿âÁ¬½Ó³Ø£¬Ê¹Ê¹ÓÃÕß¿ÉÒÔÒÔÆÕͨµÄjdbcÁ¬½ÓµÄʹÓÃÏ°¹ßÀ´Ê¹ÓÃÁ¬½Ó³Ø¡£
Êý¾Ý¿âÁ¬½Ó³ØÔÚ±àдӦÓ÷þÎñÊǾ³£ÐèÒªÓõ½µÄÄ£¿é£¬Ì«¹ýƵ·±µÄÁ¬½ÓÊý¾Ý¿â¶Ô·þÎñÐÔÄÜÀ´½²ÊÇÒ»¸öÆ¿¾±£¬Ê¹Óûº³å³Ø¼¼Êõ¿ÉÒÔÀ´Ïû³ýÕâ¸öÆ¿¾±¡£ÎÒÃÇ¿ÉÒÔÔÚ»¥ÁªÍøÉÏÕÒµ½ºÜ¶à¹ØÓ ......
1
. Õ»(stack)Óë¶Ñ(heap)¶¼ÊÇJavaÓÃÀ´ÔÚRamÖдæ·ÅÊý¾ÝµÄµØ·½¡£ÓëC++²»Í¬£¬Java×Ô¶¯¹ÜÀíÕ»ºÍ¶Ñ£¬³ÌÐòÔ±²»ÄÜÖ±½ÓµØÉèÖÃÕ»»ò¶Ñ¡£
¡¡¡¡2
. Õ»µÄÓÅÊÆÊÇ£¬´æÈ¡ËٶȱȶÑÒª¿ì£¬½ö´ÎÓÚÖ±½ÓλÓÚCPUÖеļĴæÆ÷¡£µ«È±µãÊÇ£¬´æÔÚÕ»ÖеÄÊý¾Ý´óСÓëÉú ......