title: Creating an HTML table in Java
body: <p>I have a problem in my code when I am creating a table in Java using HTML. This is my code:</p>
  
  <pre><code>for(int station : stations){
     String rowcolor = null;
     String stationnum = Integer.toString(station);
     String lastDate = pollData(station); //CALL GET LAST 
     String status = determineStatus(station, lastDate); // CALL DETERMINE STATUS
  
      switch(status){
         case " ONLINE":
             rowcolor = (" &lt;tr bgcolor=\"#5FFF33\"&gt;");
             break;
         case " OFFLINE":
             rowcolor = (" &lt;tr bgcolor=\"red\"&gt;");
             break;
         case " DELAYED":
             rowcolor = (" &lt;tr bgcolor=\"yellow\"&gt;");
             break;
     }
  
      out.write("&lt;html&gt;" +
         "&lt;body&gt;" +
         "&lt;table border ='1'&gt;" +
         "&lt;tr&gt;" +
         "&lt;td&gt;Station Number&lt;/td&gt;" +
         "&lt;td&gt;Station Name&lt;/td&gt;" +
         "&lt;td&gt;Status&lt;/td&gt;" +
         "&lt;td&gt;As of Date&lt;/td&gt;" +
         "&lt;/tr&gt;");
  
      out.write(rowcolor + "&lt;td&gt;");
      out.write(stationnum);
      out.write("&lt;/td&gt;&lt;td&gt;");
      out.write(stationnname[id]);
      out.write("&lt;/td&gt;&lt;td&gt;");
      out.write(status);
      out.write("&lt;/td&gt;&lt;td&gt;");
      out.write(lastDate);
      out.write("&lt;/table&gt;" +
         "&lt;/body&gt;" +
         "&lt;/html&gt;"); 
       id++; 
      out.close(); 
     }   
  
     }catch (IOException e) {
     System.err.println(e);
     } 
  </code></pre>
  
  <p>and this is the output:</p>
  
  <p><a href="https://i.stack.imgur.com/KKzye.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KKzye.png" alt="enter image description here"></a></p>
  
  <p>When I remove the <code>out.close();</code> part, the output is this:</p>
  
  <p><a href="https://i.stack.imgur.com/Y225Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y225Y.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the image there is a problem in creating the table. Something is not right but I can’t find a way to fix it. Please help me; thanks in advance.</p>