for loops, ifs, and mathelm/teaching/121_s12/lectures/lectur… · for loops, ifs, and math...
TRANSCRIPT
![Page 1: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/1.jpg)
For Loops, Ifs, and math February 14, 2012
CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers
Prof. Learned-Miller
![Page 2: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/2.jpg)
1
Assignments: Check OWL
![Page 3: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/3.jpg)
E-book embedded exercises They ARE graded. OWL doesn’t know about them, so it will
say confusing stuff.
2
![Page 4: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/4.jpg)
Bugs in Section 4.4 E-book Section 4.4. Problems have been
fixed.
3
![Page 5: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/5.jpg)
4
Today A break from objects, sort of. Math For loops If statements Fun with graphics
![Page 6: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/6.jpg)
Converting between types int i=3;! double d;! d=i; // No problem.! d=3.5;! i=d; // Java doesn’t like.! i= (int) d; // This is OK.!
5
![Page 7: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/7.jpg)
Some basic math int j=3;! j=j+1;! j=j*2;! j=j/j;! j=10-j;!
6
![Page 8: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/8.jpg)
Shortcuts Instead of
j=j+1;! j++;!
7
![Page 9: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/9.jpg)
Shortcuts Instead of
j=j-1;! j--;!
8
![Page 10: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/10.jpg)
Shortcuts Instead of
j=j+5;! j+=5;!
9
![Page 11: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/11.jpg)
Shortcuts Instead of
j=j-7;! j-=7;!
10
![Page 12: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/12.jpg)
Shortcuts Instead of
j=j*7;! j*=7;!
11
![Page 13: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/13.jpg)
Booleans: true or false boolean b=true;! boolean c=false;!
12
![Page 14: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/14.jpg)
Booleans: true or false boolean b;! b=(3==3); // This is weird!!
13
![Page 15: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/15.jpg)
Booleans: true or false boolean b;! b=(3==3); // This is weird!!
boolean c;! c= (3==4); // This is weirder!!
14
![Page 16: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/16.jpg)
Booleans: true or false int x=3;! int y=4;! if (x<y) !S...println(“y is bigger”);!
15
![Page 17: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/17.jpg)
Booleans: true or false
16
![Page 18: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/18.jpg)
Booleans: true or false boolean x= (3==4 || 3<4);!
17
![Page 19: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/19.jpg)
Booleans: true or false boolean x= (5>2 && 10>8);!
18
![Page 20: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/20.jpg)
Booleans: true or false boolean x= (5>2 && 10>10);!
19
![Page 21: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/21.jpg)
Booleans: true or false boolean x= (5>2 && 10>=10);!
20
![Page 22: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/22.jpg)
Booleans: true or false boolean x= !false;!
21
![Page 23: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/23.jpg)
Booleans: true or false boolean x= !!false;!
22
![Page 24: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/24.jpg)
Booleans: true or false boolean x= !!!!!!false; // 6!
23
![Page 25: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/25.jpg)
Loops! Finally! for (int i=0; i<10; i=i+1)
!System.out.println(i);!
24
![Page 26: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/26.jpg)
Loops
25
![Page 27: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/27.jpg)
Booleans: true or false
26
![Page 28: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/28.jpg)
Loops
27
![Page 29: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/29.jpg)
Ifs (or conditionals)
28
![Page 30: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/30.jpg)
Ifs (or conditionals)
29
![Page 31: For Loops, Ifs, and mathelm/Teaching/121_S12/lectures/lectur… · For Loops, Ifs, and math February 14, 2012 CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers](https://reader036.vdocument.in/reader036/viewer/2022070100/6000f709990b0e6e153b5274/html5/thumbnails/31.jpg)
30
End for today