import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Arrays {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null,"Garrett Johnston\nWeek08");
String output="";
int[] x;
x = new int[5];
x[1] = 13;
x[4] = 8;
x[0] = 3;
x[2] = 5;
JOptionPane.showMessageDialog(null, "A new int array called x was just created.\nIt was loaded with the following numbers: 13, 8, 3, 5.\nTake a look:");
for (int i= 0; i<x.length; i++) {
output = output + "x[" + i + "]= " + x[i] + "\n";
}
JOptionPane.showMessageDialog(null, output);
output = "";
JOptionPane.showMessageDialog(null, "Now I will create an array called z and set it to have 14 locations.");
JOptionPane.showMessageDialog(null, "Each location will hold the value of its location squared plus 7 times its location added to 12");
int n = 14;
double[] z = new double[n];
for (int i=0; i<z.length; i++) {
z[i] = i*i - 7*i + 12;
}
for (int i=0; i<z.length; i++) {
z[i] = i*i - 7*i + 12;
output = output + "z[" + i + "]= " + z[i] + "\n";
}
JOptionPane.showMessageDialog(null, output);
ArrayList<Rectangle> r = new ArrayList<Rectangle>();
r.add(new Rectangle());
r.add(new Rectangle());
System.out.println("from arraylist: " + r.get(1).getLength());
ArrayList<Double> dd = new ArrayList<Double>();
dd.add(4.5);
for (int i=1; i<=10;i++) dd.add((Double)(double) i);
for (int i=0; i<dd.size();i++) {
System.out.println("Arraylist sub " + i + " = " + dd.get(i));
}
}
public static double min(double... x){
double theMin;
theMin = x[0];
for (int i=1; i<x.length; i++) {
if (x[i] < theMin) theMin = x[i];
}
return theMin;
}
public static double[] getArrayOf(int n) {
double [] z = new double[n];
for (int i=0;i<n;i++) z[i] = i+1;
return z;
}
public static void displayArray(boolean[] a) {
System.out.println("Boolean version");
for (int i=0; i<a.length;i++) {
System.out.println("array[" + i + "] = " +a[i]);
}
//a = new double[15];
//a[0] = true;
}
public static void displayArray(double[] a) {
System.out.println("Double version");
for (int i=0; i<a.length;i++) {
System.out.println("array[" + i + "] = " +a[i]);
}
//a = new double[15];
//a[0] = 133.0;
}
}