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

  • 相关阅读:
    设计模式详解(图码)
    设计模式详解(图)
    Zookeeper学习
    取消单元格的点击事件
    ios 中生成随机数
    IOS 时间和时间戳之间转化
    偏好存空判断
    限制textfield的文字长度
    tabBar的图标不被系统渲染
    (转)IOS http请求的get 和 post的请求的区别
  • 原文地址:https://www.cnblogs.com/wleaves/p/10491367.html
Copyright © 2011-2022 走看看