Java小程序代码Word文档格式.docx

上传人:b****1 文档编号:4778660 上传时间:2023-05-04 格式:DOCX 页数:24 大小:17.41KB
下载 相关 举报
Java小程序代码Word文档格式.docx_第1页
第1页 / 共24页
Java小程序代码Word文档格式.docx_第2页
第2页 / 共24页
Java小程序代码Word文档格式.docx_第3页
第3页 / 共24页
Java小程序代码Word文档格式.docx_第4页
第4页 / 共24页
Java小程序代码Word文档格式.docx_第5页
第5页 / 共24页
Java小程序代码Word文档格式.docx_第6页
第6页 / 共24页
Java小程序代码Word文档格式.docx_第7页
第7页 / 共24页
Java小程序代码Word文档格式.docx_第8页
第8页 / 共24页
Java小程序代码Word文档格式.docx_第9页
第9页 / 共24页
Java小程序代码Word文档格式.docx_第10页
第10页 / 共24页
Java小程序代码Word文档格式.docx_第11页
第11页 / 共24页
Java小程序代码Word文档格式.docx_第12页
第12页 / 共24页
Java小程序代码Word文档格式.docx_第13页
第13页 / 共24页
Java小程序代码Word文档格式.docx_第14页
第14页 / 共24页
Java小程序代码Word文档格式.docx_第15页
第15页 / 共24页
Java小程序代码Word文档格式.docx_第16页
第16页 / 共24页
Java小程序代码Word文档格式.docx_第17页
第17页 / 共24页
Java小程序代码Word文档格式.docx_第18页
第18页 / 共24页
Java小程序代码Word文档格式.docx_第19页
第19页 / 共24页
Java小程序代码Word文档格式.docx_第20页
第20页 / 共24页
亲,该文档总共24页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

Java小程序代码Word文档格式.docx

《Java小程序代码Word文档格式.docx》由会员分享,可在线阅读,更多相关《Java小程序代码Word文档格式.docx(24页珍藏版)》请在冰点文库上搜索。

Java小程序代码Word文档格式.docx

classStudentextendsPeople

privateStringstudentNum;

publicStringgetStudentNum()

returnstudentNum;

publicvoidsetStudentNum(StringstrStudentNum)

studentNum=strStudentNum;

/**移位运算符测试*/

publicclassBitMotion

publicstaticvoidmain(String[]args)

inta=15;

intb=2;

intx=a<

<

b;

inty=a>

>

intz=a>

System.out.println(a+"

+b+"

="

+x);

+y);

+z);

/*

*测试位的四种运算

*/

publicclassBitOperation

intx=a&

inty=a|b;

intz=a^b;

intr=~x;

&

|"

^"

System.out.println("

~"

+x+"

+r);

*测试boolean型数据

publicclassBooleanTest

inta=20;

intb=30;

booleanx,y,z;

x=(a>

b);

y=(a<

z=((a+b)==50);

x="

y="

z="

*测试不同数制表现形式及系统的自动转化功能

*/

publicclassByteTest

bytex=22;

//十进制

bytey=022;

//八进制

bytez=0X22;

//十六进制

转换成十进制,x="

转换成十进制,y="

转换成十进制,z="

*测试char型与整数的转换

publicclassCharTest

charx='

M'

;

chary='

\120'

//请注意数字在输出时被转化成为字符

charz='

V'

字符x="

字符y="

数值Z="

+(x+z));

*常量的使用

publicclassConstants

finaldoubleCM_PER=3.14;

doubleradius=5;

thecircleareais"

+CM_PER*radius*radius);

*类常量的使用

publicclassConstants2

staticfinaldoubleCM_PER=3.14;

*两个整数相除及求余数

publicclassDivide

doublec=2;

/"

+(a/b));

%"

+(a%b));

+c+"

+(a/c));

+(a%c));

*测试double型数据类型

publicclassDoubleTest

doublex=22;

doubley=42.6D;

doublez=x*y;

double型x="

System.out.println(x+"

*"

+y+"

*测试float型数值

publicclassFloatTest

floatx=22.2F;

floaty=42.6F;

floatz=x*y;

*测试全局变量的操作

publicclassGlobalVar

inta=10;

doubleb=20;

GlobalVarglobalVar=newGlobalVar();

thevaluea="

+globalVar.a);

globalVar.print();

afterchangedthevaluea="

publicvoidprint()

theglobalvariable a="

+a+"

b="

+b);

a=30;

*测试基本类型的初始化

publicclassInitPrimitive1

bytea;

shortb;

intc;

longd;

floate;

doublef;

charg;

booleanh;

InitPrimitive1aInit=newInitPrimitive1();

aInit.print();

字节型,a="

+a);

短整型,b="

整数型,c="

+c);

长整型,d="

+d);

单精度型,e="

+e);

双精度型,f="

+f);

字符型,g="

+g);

布尔型,h="

+h);

publicclassInitPrimitive2

InitPrimitive2aInit=newInitPrimitive2();

*测试局部变量的操作

publicclassLocalVar

LocalVarlocalVar=newLocalVar();

+localVar.a);

localVar.print();

thelocalvariable a="

publicclassLocalVar2

LocalVar2localVar=newLocalVar2();

*逻辑运算符测试

publicclassLogicSign

booleanx,y,z,a,b;

a='

A'

>

'

b'

b='

R'

!

='

r'

x=!

a;

y=a&

z=a||b;

x="

y="

z="

*关系运算符测试

publicclassRelationTest

booleanx,y,z;

doublec=15;

x=a>

//true;

y=a<

//false;

z=a!

=b;

*测试自增、自减操作

publicclassSelfAction

intx=10;

inta=x+x++;

a="

intb=x+++x;

b="

intc=x+x--;

c="

intd=x+--x;

d="

*短路现象测试

publicclassShortCircuit

ShortCircuita=newShortCircuit();

if(a.test1(0)&

a.test2

(2)&

a.test3

(2))

thestatementistrue!

}else

thestatementisfalse!

publicbooleantest1(intvalue1)

test1("

+value1+"

)"

result:

"

+(value1<

1));

returnvalue1<

1;

publicbooleantest2(intvalue2)

test2("

+value2+"

+(value2<

2));

returnvalue2<

2;

publicbooleantest3(intvalue3)

test3("

+value3+"

+(value3<

3));

returnvalue3<

3;

*测试传址引用的实质

publicclassStudent

StringstrName;

StudentaStudent=newStudent();

//得到对象Student类的一个句柄aStudent

aStudent.setStudentName("

aStudentnameis"

+aStudent.getStudentName());

StudentbStudent=aStudent;

//将aStudent句柄复制给nextStudent

bStudent.setStudentName("

唐僧"

bStudentnameis"

+bStudent.getStudentName());

Stringname=aStudent.getStudentName();

//再看一下句柄aStudent的内容是否改变

afterbStudenttheaStudentnameis"

+name);

publicvoidsetStudentName(Stringname)

strName=name;

publicStringgetStudentName()

returnstrName;

*强制转型测试

publicclassTypeTran

intx;

doubley;

x=(int)22.5+(int)34.7;

//强制转型可能引起精度丢失

y=(double)x;

*测试传值引用的实质

publicclassValueReference

ValueReferenceaValue=newValueReference();

aValue.print();

intb=a;

//我们将a的值传给了a

beforechangedvaluea="

afterchangedvalue a="

*中断测试

publicclassBreakTest

for(inti=1;

i<

20;

i++)

if(i==10)

break;

System.out.print("

+i);

\ntheReptationisover!

*while循环控制结构的测试

publicclassBuyHouse

finaldoubleHOUSEFUND=200000;

doublesalary=2000;

doublefund=0;

intyears=1;

while(fund<

HOUSEFUND)

fund+=salary*0.05*12;

years++;

salary=salary*

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2