
import java.io.*; import javax.servlet.*; import javax.servlet.http.*;
public class DiceRollerServlet extends HttpServlet{ protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ PrintWriter pw = response.getWriter(); String dice1 = Integer.toString((int)(Math.random()*6)+1); String dice2 = Integer.toString((int)(Math.random()*6)+1); pw.println("
"); pw.println("dice rollerdice1 =3 dice2 =2
How is the logic executed????

The (Math.random()*6)+1 returns the random number between 1 and 6 only. so it display 3 for the first dice and 2 for another one.
For more information, visit the following link: