CS 1713 Introduction to Programming II Spring 2012 Daily Answers


Class 21:

  1. ArrayList<String> myList;
  2. true
  3. public static double[] greaterThanZeroOnly(double[] list) {
       int count = 0;
       double[] newList;
       for (int i=0; i<list.length; i++)
          if (list[i] > 0)
             count++;
       newList = new double[count];
       count = 0;
       for (int i=0; i<list.length; i++)
          if (list[i] > 0) {
             newList[count] = list[i];
             count++;
          }
       return newList;
    }
    
  4. public static void printFirstBeginsWithVowel(ArrayList list) {
       String vowels = "aeiouAEIOU";
       String thisOne;
       for (int i=0; i<list.size(); i++) {
          thisOne = list.get(i);
          if ((thisOne.length() > 0) && (vowels.indexOf(thisOne.charAt(0)) != -1)) {
             System.out.println(thisOne);
             return;
          }
       }
    }