欢迎来到天天文库
浏览记录
ID:11415326
大小:52.50 KB
页数:10页
时间:2018-07-11
《java入门基础代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、例1-1DoubleVariableDemo.javaclassDoubleVariableDemo{publicstaticvoidmain(Stringargs[]){doubledRadius=2.0d;doubledArea=Math.PI*dRadius*dRadius;System.out.println("半径为2的圆的面积:"+dArea);}}例1-2BooleanConstantDemo.javaclassBooleanConstantDemo{publicstaticvoidmain(Stringargs[]){fin
2、albooleanBFLAG=true;if(BFLAG)System.out.println("AlwaysPrintOutMe!");elseSystem.out.println("NeverPrintOutMe!");}}例1-3DecisionDemo.javaclassDecisionDemo{publicstaticvoidmain(Stringargs[]){shortx=1,y=2,z;//错误代码//z=x+y;//正确代码z=(short)(x+y);System.out.println(z);}}例1-4Integer
3、ConstantDemo.javaclassIntegerConstantDemo{publicstaticvoidmain(Stringargs[]){finalbytenMaxValue_1=100;finalshortnMaxValue_2=200;finalintnMaxValue_3=300;finallongnMaxValue_4=400;System.out.println("整数常量的nMaxValue_1值"+nMaxValue_1);System.out.println("整数常量的nMaxValue_2值"+nMaxV
4、alue_2);System.out.println("整数常量的nMaxValue_3值"+nMaxValue_3);System.out.println("整数常量的nMaxValue_4值"+nMaxValue_4);//nMaxValue_1=nMaxValue_1+1;不能更改常量的值}}例1-5DataConversionDemo.javaclassDataConversionDemo{publicstaticvoidmain(Stringargs[]){intnOp1=2;floatfOp2=2.25f;floatfResul
5、t=nOp1*fOp2;System.out.println("混合运算结果:"+fResult);}}例1-6BasicMath.javaclassBasicMath{publicstaticvoidmain(Stringargs[]){System.out.println("IntegerArithmetic");inta=1+1;intb=a*3;intc=b/4;intd=c-a;System.out.println("c="+c);System.out.println("d="+d);System.out.println("F
6、loatingPointArithmetic");doubleda=1+1;doubledb=da*3;doubledc=db/4;doubledd=dc-a;System.out.println("dc="+dc);System.out.println("dd="+dd);intx=42;doubley=42.25;System.out.println("xmod10="+x%10);System.out.println("ymod10="+y%10);}}例1-7BooleanOperatorDemo.javaclassBooleanO
7、peratorDemo{publicstaticvoidmain(Stringargs[]){intnOperator1=5;intnOperator2=10;if((nOperator1>4)&&(nOperator2>9))System.out.println("nOperator1大于4并且nOperator2大于9");elseSystem.out.println("逻辑关系判断不成立");}}例1-8BoolLogic.javaclassBoolLogic{publicstaticvoidmain(Stringargs[]){bo
8、oleana=true;booleanb=false;booleanc=a
9、b;booleand=a&b;booleane=a^b;booleanf=(!a&b)
10、(a&!b);
此文档下载收益归作者所有