Welcome to Computer Programming

 

HWJ5 - Loop exercises:

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

/**
 * HWJ5 Exercises to practice with loops
 *
 * @author (your name)
 * @version 1.9
 */
import java.util.Scanner;

public class HWJ5_Loops
{
    //class practice below
    public static void classPractice()
    {

    }

    //create a FOR loop that will print Lacrosse is not a sport 20 times
    public static void printLacrosseFor()
    {

    }

    //create a WHILE loop that will print Dont Be Late Jones 50 times
    public static void printJonesWhile()
    {

    }

    //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] (advanced - note: no comma at end)
    public static void printNumbers(int max)
    {

    }

    //that will print the odd numbers from start to end; assume start is odd.
    public static 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 static void insultUser()
    {
        Scanner scan=new Scanner(System.in);
        System.out.println("Type in a string");
        String theString=scan.nextLine();
    }

    //Create a method that will count down from 10 and then say takeoff
    public static void countDown()
    {

    }

    /*
     * this method will print out all the multiples of 11 up to 1000
     * 11,22,33, so
     */
    public static void multiplesOf11()
    {

    }

    /*
     * 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 static 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 static void upDownNumbers(int startNum)
    {

    }

    /*********************************************************************************************************************/
    // Advanced below - there are six, advanced must do between 1-6 [depending on your level]
    /*********************************************************************************************************************/

    /*
     * 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 static  void sayMyName()
    {
        Scanner scan=new Scanner(System.in);
        System.out.println("Type in a string");
        String theString=scan.nextLine();
    }

    /*
     * 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  static void findAvg()
    {
        Scanner scan=new Scanner(System.in);
        System.out.println("Type in a number");
        int x=scan.nextInt();

    }

    /*
     * 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 static 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 static void cheerLeaders(String word)
    {

    }

    //that will solve this puzzle: how many numbers between 1-1000 have a product of their digits greater than 50 like 439 is 4*3*9 which is greater than 50.
    //Print out all the numbers and say how many there were.
    public static void puzzleNumber()
    {
    }

    //Print out the first 30 prime numbers [you will need to know % (modulo operator) which gives the remainder, like 5%2 is 1 or 40%8=0 or 13%5 =3 or 24%5=4]
    public static void findPrime()
    {
    }

    //Find the smallest positive integer that if it is divided by 7, 9, and 11 the remainders are 1, 2, and 3 respectively.
    public static void puzzle2()
    {
    }

}