首页 > 其他 > 详细

Some notes in Stanford CS106A(1)

时间:2019-03-07 19:30:13      阅读:149      评论:0      收藏:0      [点我收藏+]

Karel world

1.During make a divider operation

--int x=5; double y = x/2  =>  y=2

we need sth as a double for the purpose of this operation treat it as though it were a double .

--int x=5; double y = (double)x/2  =>  y=2.5

OR

--int x=5; double y = x/2.0  =>  y=2.5

2.Define a const that can‘t be changed

private static final doule PI=3.14;

final:the value won‘t change after I give its initial value,

static:there‘s only one of these for the entire class,

private: it only lives inisde the class.

3.A buggy in boolean 

boolean p = (x !=1) || (x!=2) 

=>correct is : boolean p = (x !=1) && (x!=2) 

4.Scope: lifetime of variable 

5.While cast sth that lose information , like from double to a integer , you have to put in the CAST.

ex. double y = 3.5; int x = (int) y;

(if doesn‘t lose information like int to double , you dont have to cast.)

6.For versus while

For loop used for definite iteration(Generally we know how many times we want to iterate)

While loop used for indefinate iteration(Generally don‘t know how many times to iterate beforehand.)

 

Some notes in Stanford CS106A(1)

原文:https://www.cnblogs.com/wleaves/p/10491367.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!