email me at borlaj@portlandschools.org

Loading
notes previous (14/<14) submit the dump links  
 

Array Activities in HWJ12_Arrays

 

In a method public void practiceArrayInts() do the following:

  1. Print out all the numbers in the array.
  2. Find the sum of all the numbers in the array and print that out.//use a for loop
  3. Add 7 to every number in the array. //use a for loop
  4. [advanced] Replace all values with random ints numbers between 1 and 100 and print it out
  5. [super adv] Sort the array

In a method public void practiceArrayStrings() do the following: (

  1. Have it print out every name on its own line.
  2. Have it print out the length of each name ( ie Jeff -> 4 letters
  3. [advanced]Have it say which word comes first alphabetically (use compareTo) [hard, extra credit)
  4. [advanced] Have it reorder the words alphabetically

 

Start with the code below:

/**
 * HWJ15_Arrays - basic practice of Arrays
 * 
 * @author (your name) 
 * @version 1.17
 */
public class HWJ12_Arrays
{
    //I put the word static so that we can run this easily in bluej
    static int[] nums={10,20,30,40,50,60,70,80,90,100};
    static String[] names={"Larsen","Robert","Abukar"};

    //Print out all the numbers in the array.
    public static void classroomPlay()
    {
    }

    //Print out all the numbers in the array.
    public static void printArray()
    {
    }

    //Find the sum of all the numbers in the array and print that out.
    public static void printSum()
    {
    }

    //Add 7 to every number in the array. //YOU HAVE TO USE A FOR LOOP ( NOT FOR EACH)
    public static void add7ToAll()
    {
    }

    //Replace all values with random ints numbers between 1 and 100 and print it out //YOU HAVE TO USE A FOR LOOP ( NOT FOR EACH)
    public static void replaceWithRandom()
    {
    }

    //advanced Sort the array
    public static void sortIt()
    {
    }

    //Now Strings; Create an array with 3 names.
    //Have it print out every name on its own line. 
    public static void printNames()
    {
    }

    //Have it print out the length of each name 
    public static void printNameLengths()
    {
    }

    //[advanced]Have it say which word comes first alphabetically (use compareTo) 
    public String findFirstName()
    {
        return null;
    }

    //advanced - sort the names	
    public void sortNames()
    {
    }

    public int findRandom (int start, int end) 
    { 
        int multiplier = end-start+1; 
        int random = (int) (Math.random()*multiplier)+start; 
        return random; 
    } 
}