Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 请教高手
chuliang





发贴: 19
于 2004-10-10 15:02 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
<%@ 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

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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