欢迎来到天天文库
浏览记录
ID:50826814
大小:39.50 KB
页数:10页
时间:2020-03-15
《Java入门基础代码.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、例1-1DoubleVariableDemo.javaclassDoubleVariableDemo{publicstaticvoidmain(Stringargs[]){doubledRadius=2.0d;doubledArea=Math.PI*dRadius*dRadius;System.out.println("半径为2的圆的面积:"+dArea);}}例1-2BooleanConstantDemo.javaclassBooleanConstantDemo{publicstaticvoidmain(Stringargs[]){finalbooleanBFLAG=true;i
2、f(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-4IntegerConstantDemo.javaclassIntegerConstantDemo{
3、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值"+nMaxValue_2);System.out.println("整数常量的nMaxValue_3值"+nMaxValue_3);Sys
4、tem.out.println("整数常量的nMaxValue_4值"+nMaxValue_4);//nMaxValue_1=nMaxValue_1+1;不能更改常量的值}}例1-5DataConversionDemo.javaclassDataConversionDemo{publicstaticvoidmain(Stringargs[]){intnOp1=2;floatfOp2=2.25f;floatfResult=nOp1*fOp2;System.out.println("混合运算结果:"+fResult);}}例1-6BasicMath.javaclassBasicMath
5、{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("FloatingPointArithmetic");doubleda=1+1;doubledb=da*3;doubledc=db/4;doubledd=dc-a;System.out.println("dc="+
6、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.javaclassBooleanOperatorDemo{publicstaticvoidmain(Stringargs[]){intnOperator1=5;intnOperator2=10;if((nOperator1>4)&&(nOperator2>9))System.out.p
7、rintln("nOperator1大于4并且nOperator2大于9");elseSystem.out.println("逻辑关系判断不成立");}}例1-8BoolLogic.javaclassBoolLogic{publicstaticvoidmain(Stringargs[]){booleana=true;booleanb=false;booleanc=a
8、b;booleand=a&b;booleane=a^b;booleanf=(!a&b)
9、(a&!b);
此文档下载收益归作者所有