一个简单的猜数字游戏的小程序,怎么运行总不成功呢.请大家帮我看看是什么问题呀!
<%@ page language= "java " contentType= "text/html;charset=GB2312 "%>
<%@ page import= "java.util.* "%>
<%!
int realNum = new Random().nextInt(100) + 1;
%>
<%!
public String guess(String guessNum) {
try {
int g = Integer.parseInt(guessNum);
} catch(NumberFormatException e) {
g = -1;
g.printStackTrace();
}
if(g == realNum) {
return( "恭喜你,猜中啦! ")
}
else if(g > realNum) {
return( "猜大啦 ");
}
else if(g < realNum) {
return( "猜小啦 ");
}
else if(g == -1) {
return( "请您输入1-100之间的数 ");
}
}
%>
<%
String s = (String)request.getParameter( "number ");
s = guess(s);
out.println(s);
%>
<html>
<head>
<title> 猜数字游戏 </title>
</head>
<body>
<form action = GuessNum.jsp method= "POST ">
输入一个数字 <input name= "number "> <br>
<input type=submit value= "提交 ">
</form>
</body>
</html>
------解决方案--------------------
不知道!!!!!!!!!!!!!!!!!!!!!!!
------解决方案--------------------
问题还是挺多的.