Assignemnt #132 and Arrays with For Loops
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: Arrays with For Loops
/// File Name: Arrays with For Loops.java
/// Date Finished: 6/2/2016
import java.util.Scanner;
public class ArraysWithForLoops {
public static void main(String[] args) {
int[] myArray = new int[5];
Scanner myScanner = new Scanner(System.in);
for(int i = 0; i < myArray.length; i++) {
System.out.print("Value for item [" + (i+1) + "] = ");
myArray[i] = myScanner.nextInt();
}
System.out.println();
int total = 0;
for(int i = 0; i < myArray.length; i++) {
total += myArray[i];
}
System.out.println(total);
for(int i = myArray.length - 1; i > -1; i--) {
System.out.println("Value for item [" + (i+1) + "] = " + myArray[i]);
}
}
}
Picture of the output