Arrays program - Essay Example

Free

Extract of sample
Arrays program

The program initializes the miles at the beginning of training to 2 and 26 at the end of the training. It then calculates the daily increment within the 8 weeks in the middle of week 1 and 10. It then uses loops to sum the total mileage after initializing it to 0 then gradually adding by the values in the array. It also uses loops to find out if 4 exists in the array and ejects the loop if it exists at a given index.
BostonMarathon.java using NetBeans IDE
public class BostonMarathon {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int startMileage=2;
int endMileage=26;
//8 weeks excluding first and last week
int interval=(endMileage-startMileage)/8;
int weeklyMiles[]=new int[10];
for(int x=0;x<=9;x++){
weeklyMiles[x]=startMileage;
startMileage+=interval;
...
Download paper

Summary

This paper consist of a program which initializes the array with the appropriate number of values determining the value in the array element when the index contain 2 and calculating the sum of the total miles one spent running over the 10. …
Author : ymaggio
Download 0
Got a tricky question? Receive an answer from students like you! Try us!