Java小程序代碼_第1頁(yè)
Java小程序代碼_第2頁(yè)
Java小程序代碼_第3頁(yè)
Java小程序代碼_第4頁(yè)
Java小程序代碼_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Java小程序代碼/*第一個(gè)程序*/public class Welcome(public static void main(String args)(System.out.println(這是你的第一個(gè)程序,歡送你走入Java的大門(mén))/*學(xué)生信息導(dǎo)入*/class StudentTest(public static void main(String args)(Student aStudent = new Student();aStudent.setName(張楠);aStudent.setStudentNum(20030408);System.out.println(學(xué)生的姓名是:+ aS

2、tudent.getName() + ,學(xué)號(hào)是:+ aStudent.getStudentNum();class People(private String name;public String getName()return name;)public void setName(String strName)name = strName;)class Student extends Peopleprivate String studentNum;public String getStudentNum()return studentNum;)public void setStudentNum(S

3、tring strStudentNum)studentNum = strStudentNum;)/*移位運(yùn)算符測(cè)試*/public class BitMotion public static void main(String args)(int a = 15;int b = 2;int x = a b;int z = a b;System.out.println(a + + b + = + y);System.out.println(a + + b + = + z);)/*測(cè)試位的四種運(yùn)算*/public class BitOperation(public static void main(S

4、tring args)(int a = 15;int b = 2;int x = a & b;int y = a | b;int z = a A b;int r = -x;System.out.println(a + & + b + = + x);System.out.println(a + | + b + = + y);System.out.println(a + A + b + = + z);System.out.println(+ x + = + r);)/*測(cè)試boolean型數(shù)據(jù)*/public class BooleanTest(public static void main(St

5、ring args)(int a = 20;int b = 30;boolean x, y,z;x = (a b);y = (a b;b = R != r;x = !a;y = a & b;z = a | b;System.out.println(x = + x);System.out.println(y = + y);System.out.println(z = + z);)/*關(guān)系運(yùn)算符測(cè)試*/public class RelationTest(public static void main(String args)(boolean x, y, z;int a = 15;int b = 2

6、;double c = 15;x = a b;/true;y = a b;/false;z = a != b;/true;System.out.println(x = + x);System.out.println(y = + y);System.out.println(z = + z);)/* 測(cè)試自增、自減操作* /public class SelfAction(public static void main(String args)(int x = 10;int a = x + x+;System.out.println(a= + a);System.out.println(x= + x

7、);int b = x + +x;System.out.println(b= + b);System.out.println(x= + x);int c = x + x-;System.out.println(c= + c);System.out.println(x= + x);int d = x + -x;System.out.println(d= + d);System.out.println(x= + x);/* 短路現(xiàn)象測(cè)試* /public class ShortCircuitpublic static void main(String args)ShortCircuit a = n

8、ew ShortCircuit();if( a.test1(0) & a.test2(2) & a.test3(2)System.out.println(the statement is true!); elseSystem.out.println(the statement is false!);public boolean test1(int value1)System.out.println(test1 ( + value1 + );System.out.println(result: + (value1 1);return value1 1;public boolean test2(i

9、nt value2)System.out.println(test2 ( + value2 + );System.out.println(result: + (value2 2);return value2 2;public boolean test3(int value3)System.out.println(test3 ( + value3 + );System.out.println(result: + (value3 3);return value3 3;)/*測(cè)試傳址引用的實(shí)質(zhì)*/public class Student(String strName;public static vo

10、id main(String args)(Student aStudent = new Student();/得到對(duì)象 Student 類的一個(gè)句柄aStudentaStudent.setStudentName(張楠)System.out.println(aStudent name is + aStudent.getStudentName();Student bStudent = aStudent;/ 將 aStudent 句柄復(fù)制給 nextStudentbStudent.setStudentName(唐僧)System.out.println(bStudent name is + bStu

11、dent.getStudentName();String name = aStudent.getStudentName();/ 再看一下句柄 aStudent 的內(nèi) 容是否改變System.out.println(after bStudent the aStudent name is + name);)public void setStudentName(String name)(strName = name;public String getStudentName()(return strName;)/* 強(qiáng)制轉(zhuǎn)型測(cè)試* /public class TypeTran(public stati

12、c void main(String args)(int x;double y;x = (int)22.5 + (int)34.7;/強(qiáng)制轉(zhuǎn)型可能引起精度喪失y = (double)x;System.out.println(x = + x);System.out.println(y = + y);)/* 測(cè)試傳值引用的實(shí)質(zhì)* /public class ValueReference(int a = 10;public static void main(String args)(ValueReference aValue = new ValueReference ();aValue.print(

13、);public void print()(int b = a;/ 我們將a的信傳給了 aSystem.out.println(before changed value a = + a + , b = + b);a=30;System.out.println(after changed value a = + a + , b = + b);/*中斷測(cè)試*/public class BreakTest(public static void main(String args)(for(int i = 1; i 20; i+)(if(i = 10)break;System.out.print( +

14、i);)System.out.println(n the Reptation is over!);)/*while循環(huán)限制結(jié)構(gòu)的測(cè)試*/public class BuyHousepublic static void main(String args)final double HOUSEFUND = 200000;double salary = 2000;double fund = 0;int years = 1;while (fund HOUSEFUND)fund += salary*0.05*12;years+;salary = salary * 1.1;)System.out.printl

15、n(the total years is: + years);System.out.println(the total fund is : + fund);)/*while循環(huán)限制結(jié)構(gòu)的測(cè)試*/public class BuyHouse2public static void main(String args)final double HOUSEFUND = 200000;double salary = 2000;double fund = 0;int years = 1;dofund += salary*0.05*12;years+;salary = salary *1.1;)while (fund HOUSEFUND);System.out.println(the total years is: + years);System.out.println(the total fund is : + fund);)/*輸出數(shù)字到限制臺(tái)*/public class Circlepublic static void main(String args)for( int i = 1; i = 10; i+)System.out.print( + i);/*逗號(hào)運(yùn)算符*/public class CommaOperatorpublic static void m

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論