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

HWJ5 - 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 HWJ5_Loops
{
    //create a loop that will print I love Hani 50 times
    public void printHaniFor() 
    {
    }

    //create a loop that will print Dont eat by the computer James 50 times
    public void printJamesWhile() 
    {
    }

    //that will print the numbers from 1 to max on one line like 1,2,3,4,5,6,7,....,150 [if max was 150] (note: no comma at end)
    public void printNumbers(int max)
    {
    }

    //that will print the odd numbers from start to end; assume start is odd. 
    public void printOdds(int start, int end) 
    {
    }

    //that will insult the user and then say do you want another insult (y or n) 
    //if they say y it will repeat, if they so n it will end. [advanced - have it choose from 1 of 5 insults randomly]
    public void insultUser() 
    {
    }

    //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 [look at api]
     */
    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 below - there are six, advanced must do/really try between 1-6 [depending on your level]
    /*********************************************************************************************************************/
    /*
     * 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     
     */
    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"....
     * */
    public void cheerLeaders(String word)
    {

    }

    //Look at the loops page and advanced people must finish 2 of 4 of the bottom extra credit
}