Hello friends this is a simple program of creating a number guesser in JSP....Have a look...
<html>
<head><title>Number Guesser</title></head>
<body>
<%              int num=(int)(Math.random()*100);        %>
<h2>Welcome To Number Guesser</h2>
<br><h3>Want To Check Your Guessing Power.....GIVE IT A TRY?????</h3>
<form name="guess" action="Try.jsp?c=0" method="post">
<input type="text" name="val" value="<%=num %>" hidden>
<input type="submit" value="GO">
</form>
</body>
</html>

Try.jsp :
<html>
<head><title>Number Guesser</title></head>
<body>
<%    String str=request.getParameter("val");
         boolean flag=true;      
         int num=Integer.parseInt(str);
         int c=Integer.parseInt(request.getParameter("c"));
         if(c!=0) {
             int guess=Integer.parseInt(request.getParameter("guess"));
             if(num==guess){
                  flag=false;
          %>
<h3>Congratulation...You Successes After <%=c%> attempts</h3>
<b>Want to Improve...<a href="Number.jsp">try again</a></b>
<%       }else if(num>guess) { %>
<h3>You Guessed Lower...Try Bigger Number</h3>
<%       }else{ %>       
<h3>You Guessed Higher...Try Smaller Number</h3>
<%       }
          }
         if (flag) { c++; %>     
<h3>I Guessed a Number between 1 to 100. Try To Guess..</h3>
<form name="guess" action="Try.jsp?c=<%= c%>" method="post">
<input type="text" value="<%=num %>" name="val" hidden>
Make Your Guess : <input type="text" name="guess" size=10 maxlength=3>
<input type="submit" value="GO">
</form>
<% } %>
</body> 
</html>
Have Funs................

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.