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 閱讀(139) | 評(píng)論 (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的整型,即對(duì)象的內(nèi)容是相同的,但對(duì)象的引用卻是不同的,因此輸出結(jié)果為
          false

          所以對(duì)內(nèi)容的相同與否判斷應(yīng)該使用equals方法
          System.out.println(n1.equals(n2)) 顯示 true

          然而,當(dāng)創(chuàng)建了自己的類時(shí)
          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));
          }
          }
          結(jié)果仍為
          false
          true
          這是由于equals()的默認(rèn)行為是比較引用。所以除非在自己的新類中覆蓋equals()方法,否則不可能表現(xiàn)出希望的行為。

          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() 隨機(jī)產(chǎn)生在[0,1)的一個(gè)雙精度數(shù)

          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 閱讀(148) | 評(píng)論 (0)編輯 收藏


          ZJU 戰(zhàn)績(jī):

          1001 1045 1048 1113 1115 1180 1240 1295

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

          2006-07-17 16:12:15
          Note 16.
          總算把1295 AC了,整行讀入的語(yǔ)句是getline(cin,string &str);
          但是如果之前有類似cin<
          Note 17.
          設(shè)定小數(shù)輸出精度
          #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);
          這句話到現(xiàn)在還沒(méi)搞懂有什么用,CSDN問(wèn)了下,fixed標(biāo)志是以定點(diǎn)形式顯示浮點(diǎn)數(shù)
          還是沒(méi)理解ios::fixed到底是啥意思...
          ZJU 戰(zhàn)績(jī)

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

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

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

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

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

          2006-07-06 15:36:09

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

          1. 《C++ 程序設(shè)計(jì)(第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,有點(diǎn)麻煩,搞不定的QQ我。

          太厚了,看起來(lái)累,現(xiàn)在我一般都是看其他書,然后有問(wèn)題的再找這本書,當(dāng)字典處理。

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

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

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

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

          2006-07-04 16:02:14
          沒(méi)事干,干脆學(xué)C++了。 =_=
          先純理論地看了《C++程序設(shè)計(jì)》前幾篇。靠Object Pascal的基礎(chǔ),面向?qū)ο蟆㈩惖母拍疃寄芾斫狻9烙?jì)學(xué)起來(lái)應(yīng)該很快吧。
          Note 1.
          { }內(nèi)聲名的變量在域外無(wú)法訪問(wèn)
          這樣一來(lái),for (int i=0;i>=20;i++) {}之類的語(yǔ)句使用后變量i就沒(méi)有意義了,倒也不用像小學(xué)學(xué)Basic那樣還去管Next i之后i究竟是20還是21 =_=
          Note 2.
          ++i 和 i++ 的區(qū)別
          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.
          按任意鍵繼續(xù)
          do {} while (!kbhit());
          調(diào)用 kbhit 需聲名 >conio.h< 庫(kù),貌似是Keyboard Hit的縮寫
          Note 4.
          void delay(int n=100);
          當(dāng)調(diào)用delay時(shí),若無(wú)參數(shù),則缺省為100
          Note 5.
          參數(shù)的英文是argument... 而不是數(shù)學(xué)所用的parameter

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

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

          2007-01-21 21:57:20
          2006-07-19 22:14:33
          主站蜘蛛池模板: 海门市| 出国| 深水埗区| 宿迁市| 博湖县| 衢州市| 保靖县| 东平县| 大渡口区| 肥西县| 松潘县| 桐梓县| 通许县| 磐石市| 永昌县| 龙陵县| 敦化市| 临猗县| 上蔡县| 峨边| 乌海市| 安龙县| 且末县| 安徽省| 项城市| 泸州市| 赫章县| 尼玛县| 麻栗坡县| 馆陶县| 大连市| 东阳市| 逊克县| 鄄城县| 长丰县| 馆陶县| 定日县| 卫辉市| 平陆县| 雷山县| 涟水县|