email me at borlaj@portlandschools.org
notes previous (09/07/06) submit the dump links  
 

HWJ6 - Loop exercises:

Start with the file below and use it to create the 8 methods described.

 

 



/**
 * HW Exercises to practice with loops
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class HWJ6_Loops
{
 
    //Create a method that will countDown from 10 and then say takeoff
    public void countDown()
    {
         
    }
   
    /*
    * this method will print out all the multiples of 11 up to 1000
    * 11,22,33, so
    */   
    public void multiplesOf11()
    {
        
    }
 
    /*
     * Using the scanner class, ask the user to say my name (borland)
     * if they say anything but borland, say thats not my name, say my name!
     * and repeat this until they say my name.
     * [you can of course change it to your name]
     * for high flyers, see if you can come up w/ a way that case doesnt matter
     */
    public void sayMyName()
    {
    }
     

     
    /*
    * this method will add all the numbers between (and including
    * firstNum and endNum
    * if they put in 5,10 it would add 5,6,7,8,9,10 =45
    * int sum=0;
    * for (start at startNum go to endNum, increment one each time)
    *       sum=sum+i;
    */   
    public void firstToLastNum(int firstNum, int endNum)
    {
 
    }
 

    /*
    * this method will start at startNum and print 20 numbers more than startNum
    * then when it hits startNum+20 it will count down to startNum
    * for example you say put in 50 it will print 51 52 53...68 69 70 then 70 69... 52 51 50
   * 2 for loops   1 loop going up , one loop going down.
    * */   
    
    public void upDownNumbers(int startNum)
    {
         
    }
     
       /*
         * Using the scanner class, ask the user how many numbers you want him
         * to average.
         * Then read in that many of numbers and spit out average
         */  
    public void findAvg()
    {
      
    }
   //Advanced:
       /*
    * this method will print * then ** then *** for 10 rows
    *    so it would look like *
    *    so it would look like **
    *    so it would look like ***  and so on      
    *    ASK MEGAN FOR HELP
    */
    public void printStars()
    {
        //hint declare a variable String stars="*"; and each time in a for loop
        // say stars=stars+"*";  this would add another * to stars.
        // so your code will be in a for loop that repeats 10 times
          
    }
    
        /*
    * this method will print will print all the leters in a line of its own
    * for example if you put borland it would then print "give me a b"
    * give me a "o"
    * give me a "r"....
    * Below is a start, but not finished hint to help
    * for (i=0; word length;
    *       word.charAt(i)
    */  
    public void cheerLeaders(String word)
    {
     
    }
 
   //Look at the loops page and advanced people must finish 2 of 4 of the bottom extra credit
}
 

Extra credit (Jordan, Coy, Cyrus, Chris must do, try) ->

/*The method (real, I wrote it yesterday) will take in the correct answers in this form:   "1A2D3E4B5E6A7D8A9A10B11B12E13E14E15A16E17E18A19E20"         
and compare user answers in same form
"1A2E3E4B5E6A7D8A9A10B11B12E13E14E15A16E17E18A19E20"         
and spit out how many were wrong.*/
public void gradeQuiz(String correctAnswers, String userAnswers)
{

}