Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Servlet/JSP/JSF/JavaFX Script
打印话题 寄给朋友 订阅主题 |
作者 | 请教高手 |
chuliang
发贴: 19 |
于 2004-10-10 15:02
<%@ page contentType="text/html; charset=GBK" %> <html> <head> <title>汇率转换示例</title> </head> <body> <h3>转换后的结果如下所示:</h3> <% //取得被转换的货币 int currencyFrom=Integer.parseInt(request.getParameter("currencyFrom")); //取得转换的货币 int currencyTo=Integer.parseInt(request.getParameter("currencyTo")); //声明金额变量 double amount=0; String amountStr=""; //声明转换后金额的变量 double amountRes=0; //声明货币字符数组 String[] currencies={"人民币","英镑","美元"}; //声明汇率数组 1:double exchangeRates[][]={{1,0.083,0.125},{12,1,1.5},{8,0.667,1}}; //取得金额字符串 amoutStr=request.getParameter("amount"); try{ //将金额字符串转换为数字 amount=Double.parseDouble(amountStr); //进行货币转换操作 amountRes=amount*exchangeRates[currencyFrom][currencyTo]; //进行四舍五入操作,保留3位小数 amountRes=Math.round(amountRes*1000); amountRes/=1000; out.println("<p>"+amount+currencies[currencyFrom]+"="+amountRes+currencies[currencyTo]+"</p>"); }catch(Exception ex){ //当输入的不是数字时,产生异常 out.println("<p>金额输入框内应该输入数字.</p>"); } %> <p><a href="ExchangeRateDemo1.jsp">重新进行汇率转换操作</a></p> </body> </html> 为什么会出现这样的问题,问题如下所示: Generated servlet error: [javac] Since fork is true, ignoring compiler setting. [javac] Compiling 1 source file [javac] Since fork is true, ignoring compiler setting. [javac] D:\Tomcat4.1\work\Standalone\localhost\myweb\ExchangeRateDemo2_jsp.java:63: not a statement [javac] 1:double exchangeRates[][]={{1,0.083,0.125},{12,1,1.5},{8,0.667,1}}; [javac] ^ [javac] D:\Tomcat4.1\work\Standalone\localhost\myweb\ExchangeRateDemo2_jsp.java:63: ';' expected [javac] 1:double exchangeRates[][]={{1,0.083,0.125},{12,1,1.5},{8,0.667,1}}; [javac] ^ [javac] 2 errors 我有一点感想和初学者们同享(原创) |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
1755 | 请教高手 | chuliang | 1695 | 2004-10-10 15:02 |
1369 | Re:请教高手 | nothing | 10 | 2004-10-10 15:40 |
1534 | Re:请教高手 | chuliang | 26 | 2004-10-11 08:18 |
1451 | Re:请教高手 | nothing | 46 | 2004-10-11 08:52 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |