1. import java.util.ArrayList;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5.  
  6. public class Arrays {
  7.  
  8. public static void main(String[] args) {
  9. JOptionPane.showMessageDialog(null,"Garrett Johnston\nWeek08");
  10. String output="";
  11. int[] x;
  12. x = new int[5];
  13. x[1] = 13;
  14. x[4] = 8;
  15. x[0] = 3;
  16. x[2] = 5;
  17. 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:");
  18. for (int i= 0; i<x.length; i++) {
  19. output = output + "x[" + i + "]= " + x[i] + "\n";
  20. }
  21. JOptionPane.showMessageDialog(null, output);
  22. output = "";
  23.  
  24. JOptionPane.showMessageDialog(null, "Now I will create an array called z and set it to have 14 locations.");
  25. JOptionPane.showMessageDialog(null, "Each location will hold the value of its location squared plus 7 times its location added to 12");
  26. int n = 14;
  27. double[] z = new double[n];
  28. for (int i=0; i<z.length; i++) {
  29. z[i] = i*i - 7*i + 12;
  30. }
  31. for (int i=0; i<z.length; i++) {
  32. z[i] = i*i - 7*i + 12;
  33. output = output + "z[" + i + "]= " + z[i] + "\n";
  34. }
  35. JOptionPane.showMessageDialog(null, output);
  36.  
  37.  
  38. ArrayList<Rectangle> r = new ArrayList<Rectangle>();
  39. r.add(new Rectangle());
  40. r.add(new Rectangle());
  41. System.out.println("from arraylist: " + r.get(1).getLength());
  42. ArrayList<Double> dd = new ArrayList<Double>();
  43. dd.add(4.5);
  44. for (int i=1; i<=10;i++) dd.add((Double)(double) i);
  45. for (int i=0; i<dd.size();i++) {
  46. System.out.println("Arraylist sub " + i + " = " + dd.get(i));
  47. }
  48.  
  49.  
  50.  
  51. }
  52. public static double min(double... x){
  53. double theMin;
  54. theMin = x[0];
  55. for (int i=1; i<x.length; i++) {
  56. if (x[i] < theMin) theMin = x[i];
  57. }
  58. return theMin;
  59. }
  60. public static double[] getArrayOf(int n) {
  61. double [] z = new double[n];
  62. for (int i=0;i<n;i++) z[i] = i+1;
  63. return z;
  64. }
  65. public static void displayArray(boolean[] a) {
  66. System.out.println("Boolean version");
  67. for (int i=0; i<a.length;i++) {
  68. System.out.println("array[" + i + "] = " +a[i]);
  69. }
  70. //a = new double[15];
  71. //a[0] = true;
  72. }
  73. public static void displayArray(double[] a) {
  74. System.out.println("Double version");
  75. for (int i=0; i<a.length;i++) {
  76. System.out.println("array[" + i + "] = " +a[i]);
  77. }
  78. //a = new double[15];
  79. //a[0] = 133.0;
  80. }
  81. }