Assignment #132
Code
/// Name: Jonathan Stine
/// Period: 5
/// Program Name: Arrays with For Loops
/// File Name: ArraysWithForLoops.java
/// Date Finished: 6/6/2016
import java.util.Scanner;
public class ArraysWithForLoops {
public static void main(String[] args) {
int[] myArray = new int[5];
int total = 0;
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();
}
for(int i = 0; i < myArray.length; i++) {
total+=myArray[i];
}
System.out.println("Your total is: " + total );
for(int i = 4; i >= 0; i--) {
System.out.println("Value in item [" + (i+1) + "] = " + myArray[i]);
}
}
}
Code Output