teaching machines

CS 145 Lecture 23 – Loops V

October 24, 2014 by . Filed under cs145, fall 2014, lectures.

Agenda

TODO

What Does This Do?

  1. public static String ?(String raw) {
      String cooked = "";
      for (int i = 0; i < raw.length(); ++i) {
        if (Character.isLetterOrDigit(raw.charAt(i))) {
          cooked += raw.charAt(i);
        } else {
          cooked += "_";
        }
      }
      return cooked;
    }

  2. public static boolean ?(int n) {
      for (int i = 2; i < n; ++i) {
        if (n % i == 0) {
          return false;
        }
      }
      return true;
    }

  3. public static void ?() {
      for (int r = 1; r <= 5; ++r) {
        for (int c = r; c >= 0; --c) {
          System.out.print(c);
        }
        System.out.println();
      }
    }

Blackboxes

Code

ForFor.java

package lecture1024;

public class ForFor {
  public static void main(String[] args) {
    mystery();
  }
  
  public static void mystery() {
    for (int r = 1; r <= 5; ++r) {
      for (int c = r; c >= 0; --c) {
        System.out.print(c);
      }
      System.out.println();
    }
  }
}

Haiku

on routine:
You’reĀ an NPC
It’s weather, Cubs, work, and sleep
It’s time to break out