Week 3 notes
Week 3 notes CMPS 12A
Popular in Comp Prog Lab
Popular in ComputerScienence
This 5 page Class Notes was uploaded by Ankita Upadhyay on Monday January 25, 2016. The Class Notes belongs to CMPS 12A at University of California - Santa Cruz taught by Tantalo,P. in Winter 2016. Since its upload, it has received 8 views. For similar materials see Comp Prog Lab in ComputerScienence at University of California - Santa Cruz.
Reviews for Week 3 notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 01/25/16
Lecture 7 12016 More common format review video on matterhorn If cond 1 Stmt Else if cond 2 Stmt Compare1java Ternary conditional operator 0 Cond Exp1 exp2 Ex int x y 6 X y gt 5 1020 x gets 10 Equivalent to Int x y 6 If y gt 5 X 10 Else X 20 This operator can also be cascaded Iterative control structures 0 While for dow while 0 While cond loop repetition condition LRC Stmt loop body stmt Squaresljava example Loop control variable l i1 A very common while loop i 0 l initialize loop control variable lcp While iltn l test LRC do stuff i l increment LCV equivalent for loop for i0 iltn i l mitLCV Test LRC 14CLCV do stuff loop body Ex squaresjava 0 General for of dowhile int variable n int literal Instance vc staticclass method Doubles fed into the pow machine 0 Result is a double which is converted back into an int 0 Note while loop body may execute 0 times but dowhile loop body must execute at least once 0 Logic errors not a syntax error i 0 while ilt10 stuff i l ini nite loop computer will go forever seems broken IE Another logic error fori O i lt 10 i stuff going to execute only once not 10 times trivial cont ved In Ex Averagejava l need a scanner so that the monkey can be heard 0 Sum 0 l accumulator throw gallons of water in a bathtub o Doubleint double quot Maxjava Lecture 9 12216 Ex maxjava review this The scope of a variable is the area of the program where that variable can be accessed In java the scope of a variable extends from its declaration to the end of the block in which it was declared no furtherexamples that illustrate the notion of scope Exscope1Java Scope2java doesn t compile2 different variables names b as long as their scopes don t overlap for int i0 ilt10 i do something end of the scope of i Systemoutprintlni syntax error break and continue commands allow you to take any loop and make it exible to get out of loop make loop repetition condition false general form while cond continue lands here break lands here controlled ways to alter the function of a normal loop checkinput1java how to lter bad input out entered by the user schasnextDouble is an instance method Left of the dot instance method of scanner class hasNext instance method bc you don t see staticpeaks and tells you ahead of time if there s a tokentes whether the program will pause every token is a string entered 2 tokens while pounding bc there was a space int cant be interpreted as double but not every double can be interpreted as int 0 4 is an int 40 is a double CollatzProblemjava Switch statement a conditional operation similar to cascade of else ifs Switchexp case value1 constant expression Stmt Stmt break case value2 stmt break case value 3 stmt break default stmt break llands here Switch1java
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'