Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.*;
- @WebServlet(urlPatterns = {"/ResultadoServlet"})
- public class Binario extends HttpServlet {
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- String str = request.getParameter("N1");
- if(str != null && !str.isEmpty()){
- int number = Integer.parseInt(str);
- String bin = Integer.toBinaryString(number);
- try(PrintWriter out = response.getWriter()){
- out.println( "<p>" + number + " em binário: " + bin +" </p>" );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement