資源描述:
《java編程基礎 實例》由會員上傳分享,免費在線閱讀,更多相關內容在行業(yè)資料-天天文庫。
1、AsimpleJAVAprogram:importjava.io.*;publicclassLi2_01//Mainclassbegin{publicstaticvoid(Stringargs[]){System.out.print("ThisismyfirstJavaApplicationprogram!");System.out.print("Welldone!");}}//單個字符輸入與輸出importjava.io.*;publicclassIOTest{publicstaticvoidmain(Stringargs[]){cha
2、rc='a';System.out.print("Enteracharacterplease:");try{c=(char)System.in.read();System.out.print("Thecharacteryou'veenteredis"+c);}catch(IOExceptione){}}}//字符串輸入與輸出importjava.io.*;publicclassIOTest{publicstaticvoidmain(Stringargs[]){Stringc="";BufferedReaderbuf=newBuffered
3、Reader(newInputStreamReader(System.in));System.out.print("Enterastring:");try{c=buf.readLine();System.out.print("Thestringyou'veenteredis""+c+""");}catch(IOExceptione){}}}//接收一個整數(shù)并輸出。importjava.io.*;publicclassInt{publicstaticvoidmain(Stringargs[]){StringintNo;inti;Buff
4、eredReaderbuf=newBufferedReader(newInputStreamReader(System.in));try{System.out.print("Pleaseinputaninteger:");intNo=buf.readLine();i=Integer.parseInt(intNo);System.out.print("Theintegeryou'veenteredis:"+i+".");}catch(IOExceptione){e.printStackTrace();}}}1、字符串轉換成各種數(shù)據(jù)類型的方l
5、onglong_num=Long.parseLong(str);intint_num=Integer.parseInt(str);shortshort_num=Short.parseShort(str);bytebyte_num=Byte.parseByte(str);doubledouble_num=Double.parseDouble(str);floatfloat_num=Float.parseFloat(str);2、各數(shù)據(jù)類型所占字節(jié)數(shù)int4字節(jié)short2字節(jié)long8字節(jié)byte1字節(jié)float4字節(jié)double8字節(jié)3、
6、算術運算符+-*/%-(取負值)++--4、關系運算符>>=<<===!=5、邏輯運算符&&x&&y當x為false時,不運行y;&x&y
7、
8、x
9、
10、y當x為true時,不運行y;
11、x
12、y!!xx是false時結果為true,當x是true時結果為false;^x^yx和y均為false或者true時結果為false;6、位運算符-按位取反&按位與
13、按位或^按位異或<<左移低位添零>>右移x>>y將x向右移y位,左邊的高位添符號位>>>不帶符號右移x>>>y將x右移y位,左邊高位添零7、條件賦值運算符x?y:z8、廣義賦值運算符例:+=-=
14、……9、對象運算符XinstenceofY判斷X對象是否是類Y所創(chuàng)建。10、括號與方括號運算符()、[]//IfElse選擇語句,流程控制importjava.io.*;publicclassIfElse{publicstaticvoidmain(Stringargs[])throwsIOException{Doublex;//Student'smarkStringstr;BufferedReaderbuf=newBufferedReader(newInputStreamReader(System.in));System.out.prin
15、t("Pleaseinputthestudentmark:");x=Double.parseDouble(buf.readLine());System.out.println();if(x<0