二个浮点变量不能加吗??!!连这个都会出错.我快晕了.!!!

gameboys 2004-09-01 01:10:27
代码--------
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<html>
<body>
<%
Float c1=11.3;
Float c2=13.4;
out.print(c1+c2);
%>
</body>
</html>
--------------
错误代码


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 8 in the jsp file: /tq.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:\tomcat\work\Catalina\localhost\_\org\apache\jsp\tq_jsp.java:54: incompatible types
found : double
required: java.lang.Float
Float c1=11.3;
^



An error occurred at line: 8 in the jsp file: /tq.jsp

Generated servlet error:
D:\tomcat\work\Catalina\localhost\_\org\apache\jsp\tq_jsp.java:55: incompatible types
found : double
required: java.lang.Float
Float c2=13.4;
^



An error occurred at line: 8 in the jsp file: /tq.jsp

Generated servlet error:
D:\tomcat\work\Catalina\localhost\_\org\apache\jsp\tq_jsp.java:56: operator + cannot be applied to java.lang.Float,java.lang.Float
out.print(c1+c2);
^
3 errors


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.

...全文
60 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhushizu 2004-09-01
是呀,我也是想了好久。。关注中。。。
回复
gameboys 2004-09-01
非常感谢!!
回复
sonofdragon 2004-09-01
Float.parseFloat(a)
回复
gameboys 2004-09-01
那如果.是这样呢.

String a="11";

float a1=11.3f;

如何把a转成float呀.还要带上f

a1=a1+?
回复
gameboys 2004-09-01
原来是这样!!
回复
simon810610 2004-09-01
float c1=11.3f;后面加f,要不会被默认为double型的。
回复
kingfish 2004-09-01
float c1=11.3f;
回复
gameboys 2004-09-01
我改了.可还是错呀!!!

-------------
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 8 in the jsp file: /tq.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:\tomcat\work\Catalina\localhost\_\org\apache\jsp\tq_jsp.java:54: possible loss of precision
found : double
required: float
float c1=11.3;
^



An error occurred at line: 8 in the jsp file: /tq.jsp

Generated servlet error:
D:\tomcat\work\Catalina\localhost\_\org\apache\jsp\tq_jsp.java:55: possible loss of precision
found : double
required: float
float c2=13.4;
^
2 errors


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.
回复
mor 2004-09-01
float c1=11.3;
float c2=13.4;

Float是对象
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-01 01:10
社区公告
暂无公告