• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cant figure out how to do this loop

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my situation, I have a Java program that prints out a table and sends it to a jsp. The table prints out how many hours someone works from Date-Date. I need to do columns for each day. So it looks something like:

[Name][Company][Hours][15][16[17][18]

I aleady have the name company hours done, problem is, is that the days are dynamic. I need to be able to select from a different range of dates not always the 15-18. So how can I add a column to a table with a loop? Here is what the current code looks like:

retval = "<th>Employee</th><th>Company</th><th>Account</th><th>Billable Hours</th>"

retval is a string that is passed to the jsp to put out the column header.
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Then do something similiar inside your main loop for getting the hours...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the table header is pretty easy:


Now, to output the table, you have to nest one loop inside another. In pseudocode:

 
Patrick Mallahan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay that makes sense, i havnt had to add to a variable ever, so if you just do variable + " " it will add to any variable?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a little bit tricky sometimes, but yes. The "+" operator can catenate Strings together. It can also catenate Strings to other things -- for example, a String and an Object. It does this by converting the other thing to a String first (for an object, by using the toString() method; for primitives like ints, by using static methods like String.valueOf(int).)

But it can't catenate (for example) two Object objects, and it adds numbers rather than catenating them. One operand of "+" must be a String for this operator to imply String catenation, and remember that Java expressions are always evaluated left-to-right.

So be careful. This prints "foo12":

System.out.println("foo" + 1 + 2);

while this prints "3foo":

System.out.println(1 + 2 + foo);

This compiles:

System.out.println("foo" + new Object() + new Object());

while this doesn't:

System.out.println(new Object() + new Object() + "foo");
 
reply
    Bookmark Topic Watch Topic
  • New Topic