If your table format remains like the one you showed (just change happens in number of tr tags each with two td tags in them):-
<table>
<tr>
<td><input type="text" name="num" value="0" size="5"></td>
<td><input type="text" name="num" value="0" size="5"></td>
</tr>
<tr>
<td><input type="text" name="num1" value="0" size="5"></td>
<td><input type="text" name="num1" value="0" size="5"></td>
</tr>
</table>
Then Change your jsp code to this:-
<%
ArrayList<Integer> values= (ArrayList) request.getAttribute("valuesarray");
%>
<table>
<%
int k=0;
int noOfRows=5;
int noOftds=4;
for(int i = 0; i<noOfRows; i++)
{
if(k==values.size()){break;}
%>
<tr>
<%for(int j = 0; j<noOftds; j++){%>
<td><%=values.get(k) %></td>
<%k++%>
<%
}%>
</tr>
<% } %>
</table>
Edit summary :- I have changed code so that you can specify the no of tr tags and no of td tags in each tr tag using the variables.