Read: http://www.learnjavaonline.org/en/Arrays
Read: https://www.javatpoint.com/array-in-java
Two ways to make a new array:
int[] arr = new int[5]; //5 values, at default value, they are 0,0,0,0,0
int[] arr = {1, 2, 3, 4, 5};
You must know the size of the array when you construct it
To set an element to a different value:
arr[0] = 4;
To access the value:
int plusOne = arr[3] +1;
Types of arrays: (for example)
Every item must match type (for example, you can't have int[] arr={1, 2.5, 3.8, 4};
)
arr.length
>to access the length of the array (notice, no parenthesis!)
Java arrays are 0 based!
For example: int[] arr = {1,2,3,4,5}; last index is index 4, but the length of the array is 5!
Advanced: there is also two-dimentional arrays (like a spreadsheet)
int arr[][]={{1,2,3},{4,5,6},{7,8,9}};
if(arr[0][2]==3) //true
public static String monthName(int month)
{
//your code
//1. make an array of String. Be careful that arrays are 0 based!
//2. return by accessing the array
}
2. Go to http://codingbat.com/prob/p229948 and do the swapEnds exercise
paste your code after you get a checkmark
Created: Dexin on 3/25/18
Updated: Dexin on 12/9/18