Assignemnt #132 and Arrays With For Loops

Code

    ///Name: Daniel Tiffany-Appleton
    ///Period: 7
    ///Program Name: Arrays With For Loops
    ///File Name: ArraysWithForLoops
    ///Date Finished: 4/28/16
    
    import java.util.Scanner;
    
    public class ArraysWithForLoops {
    
        public static void main(String[] args) {
            
            //Create an integer array of 5 elements
            int[] myArray = new int[5];
            
            Scanner myScanner = new Scanner(System.in);
            
          
            //
            //  IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!
            // 
            //  Arrays start at element number 0......... NOT 1
            //
            //  IMPORTANT NOTE !!!!!!!!!!!!!!!!!!!!!!
            
            // Use a for loop to iterate through the array
            // Getting input from the user and placing into each array element
            for(int i = 0; i < myArray.length; i++) 
            {
                System.out.print("Value for item [" + (i+1) + "] = ");
                myArray[i] = myScanner.nextInt();
            }
            
            System.out.println();
            int sum = 0;
            //Print out the elements of the array in order from 0 to 4.
            for(int i = 4; i < myArray.length; i--) 
            {
                System.out.println("Value in item [" + (i+1) + "] = " + myArray[i]);
                sum = myArray[i] + sum;
                System.out.println("sum = " + sum);
            }
        }
    }


    

Picture of the output

Assignment 132