
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:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.