Welcome to Dream.In.Code
Become a Java Expert!

Join 149,533 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,523 people online right now. Registration is fast and FREE... Join Now!




For Loop Help

 
Reply to this topicStart new topic

For Loop Help, Loop in 15 min intervals

HermanW
22 May, 2007 - 10:15 AM
Post #1

New D.I.C Head
*

Joined: 26 Apr, 2007
Posts: 16


My Contributions
Hi guys just wondering, how can code a for loop to do the following:-

8:00
8:15
8:30
8:45
9:00
9:15
9:30
9:45
10:00
...
...
20:00

the following code does it hourly but how do i do it in 15min intervals? this code will be put in a JTable at col 0 with the heading "time" (making a time table...)

CODE

for(int row = 0; row < 12; row++)
{
    int t = row + 8;
    String val = t + ":00";
    table.setValueAt(val, row, 0);
}


I did a test for loop... and it works but how do implement this to my table??

CODE

for (int i=8; i<21; i++)
{
    System.out.println(i+ ":00");
    System.out.println(i+ ":15");
    System.out.println(i+ ":30");
    System.out.println(i+ ":45");
}



User is offlineProfile CardPM
+Quote Post

GWatt
RE: For Loop Help
22 May, 2007 - 12:06 PM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,356



Thanked: 31 times
Dream Kudos: 500
My Contributions
CODE

for (int i = START; i < END; i += 15)
    System.out.printf("%d:%02d\n", i / 60, i % 60);


Use the Formatter class to return a string with the times, and then iterate through the JTable, and set whatever equal to that string.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 09:02PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month