Source of TestStuff20170124.java


  1: //TestStuff20170124.java
  2: 
  3: 
  4: public class TestStuff20170124
  5: {
  6:     public static void main(String[] args)
  7:     {
  8:         int[] intArray = new int[6]; //An int array with nothing in it
  9:         for (int i=0; i<6; i++)      //Put some values into the array
 10:             intArray[i] = 2 * i;
 11:         for (int i=0; i<6; i++)      //Show that they're in there
 12:             System.out.print(intArray[i] + " ");
 13:         System.out.println();
 14:         for (int i=0; i<intArray.length; i++) //Another way to them
 15:             System.out.print(intArray[i] + " ");
 16:         System.out.println();
 17:         for (int value : intArray)   //And yet one more way to show them
 18:             System.out.print(value + " ");
 19:         System.out.println();
 20: 
 21:         //Initialize an array at the time of declaration, and then
 22:         //using a loop to "process" the values in some way 
 23:         System.out.println("----------");
 24:         String[] stringArray = {"one", "two", "three", "four", "five"};
 25:         for (String s : stringArray)
 26:             System.out.println(s.toUpperCase()); 
 27: 
 28:         if (args.length != 0)
 29:         {
 30:             for (String s : args)
 31:                  System.out.println(s);
 32:             double sum = 0;
 33:             for (String s : args)
 34:                  sum += Double.parseDouble(s);
 35:             System.out.println(sum);
 36:             /*
 37:             */
 38:         }
 39: 
 40:         System.out.println("----------");
 41:         int[][] twoDim1 = new int[2][3];
 42:         for (int row=0; row<2; row++)
 43:             for (int col=0; col<3; col++)
 44:                 twoDim1[row][col] = row + col;
 45:         for (int row=0; row<2; row++)
 46:         {
 47:             for (int col=0; col<3; col++)
 48:                 System.out.print(twoDim1[row][col] + " ");
 49:             System.out.println();
 50:         }
 51: 
 52:         System.out.println("----------");
 53:         int[][] twoDim2 = 
 54:             {
 55:                 {1, 2, 3},
 56:                 {4, 5, 6, 7},
 57:                 {8, 9}
 58:             };
 59:         for (int row=0; row<twoDim2.length; row++)
 60:         {
 61:             for (int col=0; col<twoDim2[row].length; col++)
 62:                 System.out.print(twoDim2[row][col] + " ");
 63:             System.out.println();
 64:         }
 65:     }
 66: }