1.
          If operators with the same precedence are next to each other, there associativity determines the order of evaluation. All binary operators except assignment operators are left-associative.
          Assignment operators are right-associative. Therefore, the expression
          a = b += c = 5 equivalent a = (b += (c = 5))

          If no operands hava side effects that change the value of a variable, the order of operand evaluation is irrelevant. Interesting cases arise when operands do hava a side effect. For example,

          public class TestDemo {
          public static void main(String arg[]) {
          int a = 0;
          int x = ++a + a;
          System.out.println(x);
          a = 0;
          x = a + (++a);
          System.out.println(x);
          }
          }

          The output will be:
          2
          1

          The order for evaluation operands takes precedence over the operator precedence rule. In the former case, (++a) has higher precedence than addition (+), but since a is a left-hand operand of the addition (+), it is evaluated before any part of its right-hand operand (e.g., ++a in this case).

          2.
          Converting Strings to Numbers:
          int intValue = Integer.parseInt(intString);
          double doubleValue = Double.parseDouble(doubleString);

          parseInt

          public static int parseInt(String s)
          throws NumberFormatException
          
          Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.
          Parameters:
          s - a String containing the int representation to be parsed
          Returns:
          the integer value represented by the argument in decimal.
          Throws:

          NumberFormatException - if the string does not contain a parsable integer.

          3.
          Format to keep two digits after the decimal point:
          double doubleValue = (int)(doubleValue2 * 100) / 100.0

          4.
          Computing ab:
          public static double pow(double a, double b)

          posted @ 2007-04-22 20:22 ZelluX 閱讀(140) | 評論 (0)編輯 收藏

          2007-01-20 22:38:26

          1.
          public class Equivalence {
          public static void main(String[] args){
          Integer n1 = new Integer(47);
          Integer n2 = new Integer(47);
          System.out.println(n1==n2);
          }
          }
          盡管n1, n2均為等于47的整型,即對象的內容是相同的,但對象的引用卻是不同的,因此輸出結果為
          false

          所以對內容的相同與否判斷應該使用equals方法
          System.out.println(n1.equals(n2)) 顯示 true

          然而,當創建了自己的類時
          class Value{
          int i;
          }

          public class EqualsMethod {
          public static void main(String[] args)
          {
          Value v1 = new Value();
          Value v2 = new Value();
          v1.i = v2.i = 100;
          System.out.println(v1.equals(v2));
          v1 = v2;
          System.out.println(v1.equals(v2));
          }
          }
          結果仍為
          false
          true
          這是由于equals()的默認行為是比較引用。所以除非在自己的新類中覆蓋equals()方法,否則不可能表現出希望的行為。

          2. Java provides the & and | operators. The & operator works exactly the same as the && operator, and the | operation works exactly the same as the || operator with one exception: the & and | operators always evaluate both operands. Therefore, & is referred to as the unconditional AND operator and | is referred to as conditional OR operator.

          3. Math.random() 隨機產生在[0,1)的一個雙精度數

          random

          public static double random()
          
          Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.

          When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression

          new java.util.Random
          
          This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.

          This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.

          Returns:
          a pseudorandom double greater than or equal to 0.0 and less than 1.0.
          See Also:
          Random.nextDouble()

          posted @ 2007-04-22 20:22 ZelluX 閱讀(149) | 評論 (0)編輯 收藏


          ZJU 戰績:

          1001 1045 1048 1113 1115 1180 1240 1295

          posted @ 2007-04-22 20:22 ZelluX 閱讀(87) | 評論 (0)編輯 收藏

          2006-07-17 16:12:15
          Note 16.
          總算把1295 AC了,整行讀入的語句是getline(cin,string &str);
          但是如果之前有類似cin<
          Note 17.
          設定小數輸出精度
          #include >iostream.h<
          #include >iomanip.h<
          //using namespace std 這句不能寫 =_=
          int main()
          {
          cout.setf(ios::fixed);
          cout>>setprecision(2)>>(float)0.1>>endl;//輸出0.10
          return 0;
          }
          cout.setf(ios::fixed);
          這句話到現在還沒搞懂有什么用,CSDN問了下,fixed標志是以定點形式顯示浮點數
          還是沒理解ios::fixed到底是啥意思...
          ZJU 戰績

          posted @ 2007-04-22 20:22 ZelluX 閱讀(217) | 評論 (0)編輯 收藏

          2006-07-16 21:27:43
          Note 15.
          函數后面必須跟(),經常忘了加,string.length() int main()
          還有各種邏輯表達式也得括起來
          ZJU 戰績
          1001 1045 1048 1115 1180 1240

          posted @ 2007-04-22 20:22 ZelluX 閱讀(172) | 評論 (0)編輯 收藏

          2006-07-07 19:07:30
          Note 14.
          數組名即為一個指向該數組首元素的一個指針
          e.g. 數組a[10],p = &a[0] 等價于 p = a

          posted @ 2007-04-22 20:21 ZelluX 閱讀(191) | 評論 (0)編輯 收藏

          2006-07-06 15:36:09

          周圍學C的同學貌似不少,推薦幾本好書(Ebook)

          1. 《C++ 程序設計(第2版)》

          http://www.itepub.net/html/ebookcn/2006/0429/7324.html

          閱讀需要安裝超星閱讀器

          2. C++ Primer 3rd Edition 中文版

          http://bbs.itepub.net/viewthread.php?tid=137765&highlight=C%2B%2B%2BPrimer

          閱讀需要安裝Foxit Reader,有點麻煩,搞不定的QQ我。

          太厚了,看起來累,現在我一般都是看其他書,然后有問題的再找這本書,當字典處理。

          看到指針,Pause一下,先做會兒ZJU找找感覺。
          Note 8.
          函數值參調用 void swap(int v1, int v2) {} 這樣的swap函數是不會起作用的
          形參調用的方法:
          1. 參數聲明為指針
          void pswap(int *v1, int *v2){
          int tmp=*v2;
          *v2=*v1;
          *v1=tmp;
          }
          調用函數:pswap(&a, &b);
          2. 參數聲明為引用
          void rswap(int &v1, &v2){
          int tmp=v2;
          v2=v1;
          v1=tmp
          }
          調用函數:rswap(a, b)
          Note 9.
          聲明字符串時,長度應比字符數大1,比如聲明長度為10的字符串
          char str[11]
          Note 10. (thanks to Bamboo)
          typedef int NumArray[10,10];
          相當于Pascal中的
          type
          NumArray = array[0..9, 0..9] of integer;
          Note 11.
          邏輯表達式都得加( )
          Note 12.
          ''表示字符 ""表示字符串
          Note 13.
          被庫函數郁悶了一下午,總算搞定了
          使用string時,除了#include >string.h<外,還需using namespace std;
          cin<<到一個string變量時總是報錯,搞了半天原來應該聲明
          #include >iostream<而不是#include >iostream.h<

          posted @ 2007-04-22 20:21 ZelluX 閱讀(197) | 評論 (0)編輯 收藏

          2006-07-05 21:18:19
          下載了1043頁的《C++ Primer》電子版,開始啃……
          Note 6.
          "two" "some" = "twosome "
          Note 7.
          3 + 5 和 3.0 + 5.0 中的"+"是兩個不同的操作,加法操作被重載,以便適應不同的操作數類型。

          posted @ 2007-04-22 20:21 ZelluX 閱讀(144) | 評論 (0)編輯 收藏

          2006-07-04 16:02:14
          沒事干,干脆學C++了。 =_=
          先純理論地看了《C++程序設計》前幾篇。靠Object Pascal的基礎,面向對象、類的概念都能理解。估計學起來應該很快吧。
          Note 1.
          { }內聲名的變量在域外無法訪問
          這樣一來,for (int i=0;i>=20;i++) {}之類的語句使用后變量i就沒有意義了,倒也不用像小學學Basic那樣還去管Next i之后i究竟是20還是21 =_=
          Note 2.
          ++i 和 i++ 的區別
          int a,b
          a=b=0;
          b=a++; //b=0; 可以理解為b=a, a+=1;
          cout>>a>>endl; //a=1;
          cout>>b>>endl; //b=0;
          a=b=0;
          b=++a; //b=0; 可以理解為a+=1,b=a;
          cout>>a>>endl; //a=1;
          cout>>b>>endl; //b=1;
          Note 3.
          按任意鍵繼續
          do {} while (!kbhit());
          調用 kbhit 需聲名 >conio.h< 庫,貌似是Keyboard Hit的縮寫
          Note 4.
          void delay(int n=100);
          當調用delay時,若無參數,則缺省為100
          Note 5.
          參數的英文是argument... 而不是數學所用的parameter

          posted @ 2007-04-22 20:21 ZelluX 閱讀(217) | 評論 (0)編輯 收藏

          僅列出標題
          共39頁: First 上一頁 31 32 33 34 35 36 37 38 39 
          posts - 403, comments - 310, trackbacks - 0, articles - 7
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          2007-01-21 21:57:20
          2006-07-19 22:14:33
          主站蜘蛛池模板: 米泉市| 方正县| 聊城市| 海口市| 沙坪坝区| 炉霍县| 竹山县| 米脂县| 沙田区| 黑龙江省| 南康市| 开封市| 沂源县| 绍兴县| 灵山县| 平邑县| 上高县| 安泽县| 天峻县| 乐亭县| 富源县| 通海县| 庆云县| 蛟河市| 宜川县| 东至县| 蒲城县| 龙门县| 景东| 长泰县| 叶城县| 锡林浩特市| 南郑县| 兴城市| 汕头市| 新巴尔虎右旗| 祁连县| 合水县| 普陀区| 榆树市| 讷河市|