Padd Solutions

Converted by Falcon Hive

public class LotsOfStuff
{
    public static void main (String[] args)
    {
        /** ************* Practice ******************
         *  We'll do this one together.  We're going to
         *  add up all the values that i will be in the
         *  following loop.  We're also going to count
         *  the number of even numbers that i will be.
         */
        System.out.println ("Practice Section\n");
        int count = 0;
        int sum = 0;
        int evens = 0;
       
        for (int i = 2; i < 99; i++)
        {
            count++;
            sum += i;
           
            if (i% 2 == 0)
            {
                evens++;
            }
        }
       
        System.out.println ("Iterations: "+count);
        System.out.println ("Sum: "+sum);
        System.out.println ("Evens: "+evens);
       
       
       
        /** ************** Part 1 *******************
         *  Print how many times this loop runs
         */
        System.out.println ("\n\nPart 1\n");
       
        count = 0;
       
        for (int i = 0; i < 99; i += 3)
        {
            count++;
        }
       
        System.out.println ("Iterations: "+count);
       
       
        /** ************** Part 2 *******************
         *  Print the sum of all numbers that i will be
         */
        System.out.println ("\n\nPart 2\n");
       
        sum = 0;
       
        for (int i = 100; i > 50; i--)
        {
            sum += i;
        }
       
        System.out.println ("Sum: "+sum);

       
        /** ************** Part 3 *******************
         *  Print the number of even numbers that i has been
         */
        System.out.println ("\n\nPart 3\n");
       
        evens = 0;
       
        for (int i = 0; i < 50; i += 3)
        {
           if (i% 2 == 0)
           {
               evens++;
           }
        }
       
        System.out.println ("Evens: "+evens);
       
       
        /** ************** Part 4 *******************
         *  Print the number of times this loop runs
         *  also, print the sum of all numbers that i will be
         */
        System.out.println ("\n\nPart 4\n");
       
        count = 0;
        sum = 0;
       
        for (int i = 500; i <= 0; i -= 45)
        {
            count++;
            sum += i;
        }
       
        System.out.println ("Iterations: "+count);
        System.out.println ("Sum: "+sum);
       
        /** ************** Part 5 *******************
         *  Print the total number of times that loop runs
         *  Also, print the total number of even numbers
         *  And, print the total number of odd numbers
         */
        System.out.println ("\n\nPart 5\n");
       
        count = 0;
        evens = 0;
        int odds = 0;
       
        for (int i = 30; i <= 60; i += 3)
        {
            count++;
           
            if (i% 2 == 0)
            {
                evens++;
            }
           
            if (i% 2 != 0)
            {
                odds++;
            }
        }
       
        System.out.println ("Iterations: "+count);
        System.out.println ("Evens: "+evens);
        System.out.println ("Odds: "+odds);
       
       
        /** ************** Part 6 *******************
         *  Make a loop that will count to 100 by 5's
         *  like 5 10 15 20... 100
         *  Also, make it print that the sum of all of those numbers
         */
        System.out.println ("\n\nPart 6\n");
       
        int crap = 5;
        int stop = 20;
        sum = 0;
        for (int i = 1; i <= stop; i = i + 1)
        {
            System.out.print (crap* i+ " ");
            int stuff = crap * i;
            sum += stuff;
        }
       
        System.out.println ();
        System.out.print ("The sum of all numbers is: "+sum);
    }
}

(0) Comments

Post a Comment