Assignemnt #130 and Making Arrays
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: Making Arrays
///File Name: MakingArrays
///Date Finished: 4/12/16
public class MakingArrays {
public static void main(String[] args) {
//Here we created an integer array with 5 elements
//int[] intArray = {4, 12, 15, 23, 100000};
//Here we created an integer array with 5 empty spots that can be filled with any integers
//int[] anotherIntArray = new int[5];
//Here is one way to initialize each of those empty spots
//anotherIntArray[0] = -11;
//anotherIntArray[1] = 0;
//anotherIntArray[2] = 211;
//anotherIntArray[3] = 17;
//anotherIntArray[4] = -1990;
//Here we created a String array with 3 elements
//String[] stringArray = {"Hello", ",", "world!"};
//Here we created a String array with 3 empty spots
//String[] anotherStringArray = new String[3];
//You can initialize each empty spot the same as before, only with strings here
//anotherStringArray[0] = "Mr.";
//anotherStringArray[1] = "Joshua";
//anotherStringArray[2] = "Davis";
//Using arrays in output is pretty much what you would expect
//System.out.println(intArray[0] + " + " + intArray[4] + " = " + (intArray[0] + intArray[4]));
//Sometimes things can be a bit weird
//Here the intArray[0] + intArray[4] are treated as strings
//System.out.println(intArray[0] + " + " + intArray[4] + " = " + intArray[0] + intArray[4]);
//Output with String arrays
//System.out.println(stringArray[0] + stringArray[1] + " " + stringArray[2]);
int[] intArray = {6, 42, 9};
System.out.println("Let's count " + intArray[0] + ", " + intArray[1] + ", " + intArray[2] + ". That's not right.");
String[] stringArray = new String[3];
stringArray[0] = "I";
stringArray[1] = "want";
stringArray[2] = "cake.";
System.out.println("Want do you want? " + stringArray[0] + " " + stringArray[1] + " " + stringArray[2]);
}
}
Picture of the output