Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <%@page import="java.util.Random" %>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title>Zadanie 3</title>
  9. </head>
  10. <body>
  11. <%! Random generator = new Random();
  12. int losowa = generator.nextInt(100);
  13. int liczbaprob = 1;
  14. %>
  15. <% request.setAttribute("zagadka",losowa);%>
  16. <form action="zadanie3.jsp" method="post">
  17. Podaj liczbe:<input type="Text" name="liczba" id="liczba"required>
  18. <input type="Submit" value="Zgaduj">
  19. </form>
  20. <% String liczba = request.getParameter("liczba");
  21. int zagadka = Integer.parseInt(request.getAttribute("zagadka").toString());
  22. if (liczba != null){
  23. int liczba_int=Integer.parseInt(liczba);
  24. if (liczba_int < zagadka) {
  25. out.println("Twoja liczba ("+ liczba +") jest <b>mniejsza</b> niz zagadka");
  26. liczbaprob=liczbaprob+1;
  27. }
  28. else if (liczba_int > zagadka) {
  29. out.println("twoja liczba ("+ liczba +") jest <b>wieksza</b> niz zagadka");
  30. liczbaprob=liczbaprob+1;
  31. }
  32. else {
  33. if(liczbaprob!=1)
  34. out.println("Brawo, zgadla(e)s po "+liczbaprob+" probach! Jeszcze raz?");
  35. else out.println("Brawo, zgadla(e)s po "+liczbaprob+" probie! Jeszcze raz?");
  36. liczbaprob=1;
  37. losowa = generator.nextInt(100);
  38. session.removeAttribute("zagadka");
  39. session.setAttribute("zagadka", losowa);
  40. }
  41. }
  42. %>
  43. </body>
  44. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement