aspose file tools*
The moose likes Java in General and the fly likes cant figure out how to do this loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "cant figure out how to do this loop" Watch "cant figure out how to do this loop" New topic
Author

cant figure out how to do this loop

Patrick Mallahan
Ranch Hand

Joined: Apr 22, 2005
Posts: 69
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.
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264


Then do something similiar inside your main loop for getting the hours...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Well, the table header is pretty easy:


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



[Jess in Action][AskingGoodQuestions]
Patrick Mallahan
Ranch Hand

Joined: Apr 22, 2005
Posts: 69
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
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cant figure out how to do this loop