Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <%@page import="java.util.Random" %>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Zadanie 3</title>
- </head>
- <body>
- <%! Random generator = new Random();
- int losowa = generator.nextInt(100);
- int liczbaprob = 1;
- %>
- <% request.setAttribute("zagadka",losowa);%>
- <form action="zadanie3.jsp" method="post">
- Podaj liczbe:<input type="Text" name="liczba" id="liczba"required>
- <input type="Submit" value="Zgaduj">
- </form>
- <% String liczba = request.getParameter("liczba");
- int zagadka = Integer.parseInt(request.getAttribute("zagadka").toString());
- if (liczba != null){
- int liczba_int=Integer.parseInt(liczba);
- if (liczba_int < zagadka) {
- out.println("Twoja liczba ("+ liczba +") jest <b>mniejsza</b> niz zagadka");
- liczbaprob=liczbaprob+1;
- }
- else if (liczba_int > zagadka) {
- out.println("twoja liczba ("+ liczba +") jest <b>wieksza</b> niz zagadka");
- liczbaprob=liczbaprob+1;
- }
- else {
- if(liczbaprob!=1)
- out.println("Brawo, zgadla(e)s po "+liczbaprob+" probach! Jeszcze raz?");
- else out.println("Brawo, zgadla(e)s po "+liczbaprob+" probie! Jeszcze raz?");
- liczbaprob=1;
- losowa = generator.nextInt(100);
- session.removeAttribute("zagadka");
- session.setAttribute("zagadka", losowa);
- }
- }
- %>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement