【正文】
0。for(inti=start。i=0。i){243. c=(i)。244. if(c==39。.39。){245. if(dotIndex!=1)246. thrownewIllegalArgumentException(247. therehavemorethan1dotsinthenumber.)。248. else249. dotIndex=i。250. }elseif(!(c)){251. returni+1。252. }elseif(i==0){253. return0。254. }255. }256. thrownewIllegalArgumentException(notanumber.)。257. }258. 259. /**260. *readthenextnumber261. *@paraminput262. *@paramstart263. *@return264. *@throwsIllegalArgumentException265. */266. privatestaticintreadDouble(Stringinput,intstart)267. throwsIllegalArgumentException{268. intlen=()。269. intdotIndex=1。270. charc。271. for(inti=start。ilen。++i){272. c=(i)。273. if(c==39。.39。){274. if(dotIndex!=1)275. thrownewIllegalArgumentException(276. therehavemorethan1dotsinthenumber.)。277. elseif(i==len1)278. thrownewIllegalArgumentException(279. notanumber,dotcan39。tbethelastpartofanumber.)。280. else281. dotIndex=i。282. }elseif(!(c)){283. if(dotIndex==1||idotIndex1)284. returni。285. else286. thrownewIllegalArgumentException(287. notanumber,dotcan39。tbethelastpartofanumber.)。288. }elseif(i==len1){289. returnlen。290. }291. }292. 293. thrownewIllegalArgumentException(notanumber.)。294. }295. /**296. *returntrueifthecharacterisanoperator.297. *@paramc298. *@return299. */300. privatestaticbooleanisOperator(charc){301. return(c==39。+39。||c==39。39。||c==39。*39。||c==39。/39。)。302. }303. }下面是程序運(yùn)行結(jié)果(綠色為用戶輸入):== usage ==input the expressions, and then the program will calculate them and show the result.input 39。bye39。 to exit.input an expression:+Polish Notation (PN):+ the result is Reverse Polish Notation (RPN): +the result is input a new expression:5*(+)/(15+)Polish Notation (PN):/ * 5 + + 1 5 the result is Reverse Polish Notation (RPN):5 + * 1 5 + /the result is input a new expression:1+((2+3)*4)5Polish Notation (PN): + 1 * + 2 3 4 5the result is 16Reverse Polish Notation (RPN):1 2 3 + 4 * + 5 the result is 16input a new expression:byeprogram exits