Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple For Loop Question  RSS feed

 
Brian Swingle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, guys i'm having a brain fart. I know that comparing an int to an integer is something like this. But it mot working can someone take a look at this and give me a hint.
String Quantity = req.getParameter("Quantity");
Integer Quan = Integer.valueOf(Quantity);
for (int i = 0; (Quan.compareTo(i)==0); i++)
{
System.out.println("" + i + "");
out.println("<Form>");
out.println("1) <input type = text></input><br>");
out.println("<input type = radio></input> <input Type = checkbox></input> <input type = text></input>");
out.println("<br><input type = radio></input> <input Type = checkbox></input> <input type = text></input>");
out.println("<br><input type = radio></input> <input Type = checkbox></input> <input type = text></input>");
out.println("<br><input type = radio></input> <input Type = checkbox></input> <input type = text></input>");
out.println("</form>");
}
Thanks Brian
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can avoid dealing with the Integer wrapper completely with one of:

I'd also highly recommend following standard Java naming conventions and not capitalizing variable names.
hth,
bear
 
Brian Swingle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for all your help that worked perfectly.
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PS Don't forget to check for missing and malformed data. You always should do this before using a request parameter. In this case, put the call to Integer.parseInt inside a try/catch block that catches NumberFormatException.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!