Difference between revisions of "Java Arrays Assignment"

From WLCS
(Directions)
 
(4 intermediate revisions by 2 users not shown)
Line 16: Line 16:
 
# Download [[Media:ArrayFun.java]]
 
# Download [[Media:ArrayFun.java]]
 
# Read, analyze, and execute [[Media:ArrayFun.java]]
 
# Read, analyze, and execute [[Media:ArrayFun.java]]
 +
<!--
 
# Modify the program in the following manner:
 
# Modify the program in the following manner:
 
## Add a new loop that determines the number of values in the list that are equal to the average.
 
## Add a new loop that determines the number of values in the list that are equal to the average.
 
## Add a System.out.println() statement that displays the number of values in the list that are equal to the average.
 
## Add a System.out.println() statement that displays the number of values in the list that are equal to the average.
 
## As a simple test case, run the program on a list of size four whose values are 2, 1, 2, and 3. Also run the program on a list of size three whose values are 4, 0, and 2.
 
## As a simple test case, run the program on a list of size four whose values are 2, 1, 2, and 3. Also run the program on a list of size three whose values are 4, 0, and 2.
 +
-->
 
# Modify the program to determine and display the minimum in the list.  
 
# Modify the program to determine and display the minimum in the list.  
 
## The standard approach to such a task is to initialize min with the value of the first element in the list (i.e., number[0]).  
 
## The standard approach to such a task is to initialize min with the value of the first element in the list (i.e., number[0]).  
Line 26: Line 28:
 
### If an element is found to be less than min, the value of min is updated.  
 
### If an element is found to be less than min, the value of min is updated.  
 
## After the loop completes, the minimum value is definitely stored in min.
 
## After the loop completes, the minimum value is definitely stored in min.
 +
# Demo the your modified version of [[Media:ArrayFun.java]]

Latest revision as of 14:50, 18 September 2015

Objective

  • You will learn to declare arrays in Java
  • You will learn to iterate through arrays in Java
  • You will learn to manipulate arrays in Java

Resources

Directions

  1. Download Media:Sum.java
  2. Read, analyze, and execute Media:Sum.java
  3. Fix Media:Sum.java so that it compiles and executes properly
  4. Demo the fixed Media:Sum.java


  1. Download Media:ArrayFun.java
  2. Read, analyze, and execute Media:ArrayFun.java
  3. Modify the program to determine and display the minimum in the list.
    1. The standard approach to such a task is to initialize min with the value of the first element in the list (i.e., number[0]).
    2. A loop then considers the other elements in the list. (traverse the list)
      1. Each of these elements is tested in turn to determine whether it is less than min.
      2. If an element is found to be less than min, the value of min is updated.
    3. After the loop completes, the minimum value is definitely stored in min.
  4. Demo the your modified version of Media:ArrayFun.java