zoukankan      html  css  js  c++  java
  • Some notes in Stanford CS106A(1)

    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.)

  • 相关阅读:
    iOS的文字自适应
    指向指针的指针
    NSString的创建
    Foundation-常用结构体
    Foundation summary
    成员变量补充
    Block^
    Protocol
    Category-分类
    李明杰要在广州开课啦
  • 原文地址:https://www.cnblogs.com/wleaves/p/10491367.html
Copyright © 2011-2022 走看看