30 lines
862 B
Java
30 lines
862 B
Java
/*
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
*/
|
|
package lab15_calebfontenot;
|
|
|
|
/**
|
|
*
|
|
* @author caleb
|
|
*/
|
|
public class Array3 {
|
|
public static void main(String[] args)
|
|
{
|
|
int[] values = new int[5];
|
|
//Init array with correct value of i plus the value of the previous array element
|
|
for (int i = 1; i < values.length; i++) {
|
|
values[i] = i + values[i - 1];
|
|
}
|
|
|
|
// put in the first array element the second plus the last array elements
|
|
values[0] = values[1] + values[values.length -1];
|
|
|
|
// print the array
|
|
for (int i = 0; i < values.length; i++) {
|
|
System.out.println(values[i]);
|
|
}
|
|
|
|
}
|
|
}
|