DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    21

    Unhappy Help with for and while loop

    I want to rewrite the body of a code so that the For loop is replaced with an equivalent while can someone please help with a while loop ASAP!!
    Code:
    /**
         * Print the hourly counts.
         * These should have been set with a prior
         * call to analyzeHourlyData.
         */
        
    public void printHourlyCounts()
        {
            
            System.out.println("Hr: Count");
            for(int hour = 0; hour < hourCounts.length; hour++) {
                System.out.println(hour + ": " + hourCounts[hour]);
            }
           
        }
    
    and also how do i rewrite this code with a FOR LOOP?!?
    public void listNotes()
        {
            int index = 0;
            while(index < notes.size()) {
                  System.out.println(notes.get(index));
                   index++;
               }
         }
    [ArchAngel added CODE tags]

  2. #2
    Join Date
    Mar 2003
    Posts
    834
    What problem are you having?
    ArchAngel.
    O:-)

  3. #3
    Join Date
    Nov 2003
    Posts
    7
    while loops and for loops are pretty much the same. I have no clue what your first example is, but here is what you could do with your second one:

    for(int index =0; index<notes.size();index++)
    System.out.println(notes.get(index));

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links