CS 121 – Intro to Programming:Java - Lecture 11 Announcements Ch 5 OWL assignment due Friday, 5 PM Programming assignment 4 due next Wednesday (group session with me today, 2 PM CS BLDG 151) Grading complete on prog 1, 2 Midterm up tomorrow (window: 5 Fri - noon Monday)
While loops - Java’s other important looping construct int j = 1; // control variable while (j 3){ System.out.println(n); n = n - 1; }
What about this loop? int n = 1; while (n != 10){ System.out.println(n); n = n + 2; }
Suppose you have a 300,000 word dictionary (in alphabetical order). How many comparisons does it take to find a word?
public class SplitTest{ public static void main(String[] args){ int num = 300000; int splitCount = 0; while (num > 1){ num = num/2; splitCount++; } System.out.println("split count:" + splitCount); } } ----> number of splits: 18
Wwhat does this method do (assume in SimpleDice class)? public int huh(int big){ int count = 0; int total = 0; while(total < big){ count = count + 1; total = total + throwDice(); } return count; }
Palindromes -same forwards and backwards(throw out: caps, punctuation, spaces: ablewasiereisawelba) Otto Sit on a potato pan, Otis Doc: note I dissent. A fast never prevents a fatness. I diet on cod. Live dirt up a sidetrack carted is a putrid evil A man a plan a canal, Panama! Able was I ere I saw Elba Remarkable was I ere I saw Elba, Kramer