Primeno.jsp
<html><head><title>PRIME NUMBER GENERATION IN JSP</title></head>
<body>
<form method="get">
<h3> Enter the limit for prime number generation:<input type="text" name="limit"></h3>
</form>
<h3>
<%
String s = request.getParameter("limit");
if (s != null) {
%>
<%@ page import = "java.io.*"%>
<%@ page import = "java.lang.*"%>
<%
int n=0;
n=Integer.parseInt(s);
int num=0;
String prime="";
for(int i=1;i<= n;i++)
{
int counter=0;
for(num =i; num>=1; num--)
{
if(i%num==0)
{
counter = counter + 1;
}
}
if (counter ==2 )
{
prime = prime + i + " ";
}
}
out.println("Prime numbers from 1 to"+ n+" are :");
out.println(prime);
}
%>
</h3>
</body>
</html>
No comments:
Post a Comment