吐血共享我的java学习代码笔记.docx

上传人:b****2 文档编号:2017202 上传时间:2023-05-02 格式:DOCX 页数:22 大小:20.42KB
下载 相关 举报
吐血共享我的java学习代码笔记.docx_第1页
第1页 / 共22页
吐血共享我的java学习代码笔记.docx_第2页
第2页 / 共22页
吐血共享我的java学习代码笔记.docx_第3页
第3页 / 共22页
吐血共享我的java学习代码笔记.docx_第4页
第4页 / 共22页
吐血共享我的java学习代码笔记.docx_第5页
第5页 / 共22页
吐血共享我的java学习代码笔记.docx_第6页
第6页 / 共22页
吐血共享我的java学习代码笔记.docx_第7页
第7页 / 共22页
吐血共享我的java学习代码笔记.docx_第8页
第8页 / 共22页
吐血共享我的java学习代码笔记.docx_第9页
第9页 / 共22页
吐血共享我的java学习代码笔记.docx_第10页
第10页 / 共22页
吐血共享我的java学习代码笔记.docx_第11页
第11页 / 共22页
吐血共享我的java学习代码笔记.docx_第12页
第12页 / 共22页
吐血共享我的java学习代码笔记.docx_第13页
第13页 / 共22页
吐血共享我的java学习代码笔记.docx_第14页
第14页 / 共22页
吐血共享我的java学习代码笔记.docx_第15页
第15页 / 共22页
吐血共享我的java学习代码笔记.docx_第16页
第16页 / 共22页
吐血共享我的java学习代码笔记.docx_第17页
第17页 / 共22页
吐血共享我的java学习代码笔记.docx_第18页
第18页 / 共22页
吐血共享我的java学习代码笔记.docx_第19页
第19页 / 共22页
吐血共享我的java学习代码笔记.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

吐血共享我的java学习代码笔记.docx

《吐血共享我的java学习代码笔记.docx》由会员分享,可在线阅读,更多相关《吐血共享我的java学习代码笔记.docx(22页珍藏版)》请在冰点文库上搜索。

吐血共享我的java学习代码笔记.docx

吐血共享我的java学习代码笔记

intmax=Integer.MAX_VALUE;//求出最大值

System.out.println("整型的最大值:

"+max);

charch1='a';//字符是使用”'“括起来的数据

charch2=97;//通过数字定义字符变量

charch1='\"';//表示的是一个"

charch2='\\';//表示的是一个、

floatnum=3.0f;//定义一个浮点型变量

booleanflag=true;//定义布尔型变量

System.out.println("flag="+flag);//打印输出

Stringstr="lixinghua";//定义字符串变量

intx=30;

str=str+x;//修改str的内容并将内容重新给str变量

publicstaticvoidmain(Stringargs[]){

for(inti=0;i<10;i++){

if(i==3){

continue;

}

System.out.println("i="+i);结果:

没有i=3

if(x%2==1){//判断于是是否为1

System.out.println("x是奇数!

");//如果余数为1表示奇数

max=x>y?

x:

y;//通过三目运算符求出最大值

intscore[]=null;//声明数组

score=newint[3];//为数组开辟空间,大小为3

System.out.println("数组长度为:

"+score.length);

intscore[]={91,92,93,94,95,96};//使用静态初始化声明数组

for(intx=0;x

System.out.println("score["+x+"]="+score[x]);

publicstaticvoidmain(Stringargs[]){

intscore[]={67,89,87,69,90,100,75,90};//使用静态初始化声明数组

intmax=0;//保存数组中的最大值

intmin=0;//保存数组中的最小值

max=min=score[0];

for(intx=0;x

if(score[x]>max){

max=score[x];

}

elseif(score[x]

min=score[x];

}

}

System.out.println("最高成绩:

"+max);

System.out.println("最低成绩:

"+min);

}

publicstaticvoidmain(Stringargs[]){

intscore[]={67,89,87,69,90,100,75,90};//使用静态初始化声明数组

for(inti=1;i

for(intj=0;j

if(score[i]

inttemp=score[i];//中间变量

score[i]=score[j];

score[j]=temp;

}

}

}

for(inti=0;i

System.out.print(score[i]+"\t");

}

publicstaticvoidmain(Stringargs[]){

intscore[][]=newint[4][3];//声明并实例化二维数组

score[0][1]=30;//为数组中的内容赋值

score[1][0]=31;//为数组中的内容赋值

score[2][2]=32;//为数组中的内容赋值

score[3][1]=33;//为数组中的内容赋值

score[1][1]=30;//为数组中的内容赋值

for(inti=0;i

for(intj=0;j

System.out.print(score[i][j]+"\t");

}

System.out.println("");

}

}

publicstaticvoidmain(Stringargs[]){

intscore[][]={

{67,61},{78,89,83},{99,100,98,66,95}

};//静态初始化完成,每行的数组元素个数不一样1

for(inti=0;i

for(intj=0;j

System.out.print(score[i][j]+"\t");

}

System.out.println("");

}

}

};

publicstaticvoidmain(Stringargs[]){

intscore[][][]={

{

{5,1},{6,7}

},

{

{9,4},{8,3}

}

};//静态初始化完成,每行的数组元素个数不一样1

for(inti=0;i

for(intj=0;j

for(intk=0;k

{

System.out.println("score["+i+"]["+j+"]["+k+"]="+score[i][j][k]+"\t");

}

}

}

}

};

publicstaticvoidmain(Stringargs[]){

PrintInto();

System.out.print("您好!

");

}

publicstaticvoidPrintInto(){

charc[]={'h','e','l','o'};

for(intx=0;x

System.out.print(c[x]);

}

System.out.println();

}

};

publicstaticvoidmain(Stringargs[]){

System.out.println("计算结果:

"+sum(100));//调用操作

}

publicstaticintsum(intnum){//定义方法用于求和操作

if(num==1){//判断是否是加到了最后一个数

return1;

}else{

returnnum+sum(num-1);//递归调用

}

}

publicstaticvoidmain(Stringargs[]){

System.out.print("不传递参数(fun()):

");

fun();//不传递参数

System.out.print("\n传递一个参数(fun

(1)):

");

fun

(1);//传递一个参数

System.out.print("\n传递五个参数(fun(1,2,3,4,5)):

");

fun(1,2,3,4,5);

}

publicstaticvoidfun(int...arg){//可变参数

for(inti=0;i

System.out.print(arg[i]+"、");

}

}

};

publicstaticvoidfun(int...arg){//可变参数

for(intx:

arg){//使用foreach输出输出

System.out.print(x+"、");

}

classPerson{

Stringname;//声明姓名属性

intage;//声明年龄属性

publicvoidtell(){//取得信息

System.out.println("姓名:

"+name+",年龄:

"+age);

}

Personper=newPerson();

per.name=”张三”;

per.age=30;

per.tell();

classPerson{

privateStringname;//声明姓名属性

privateintage;//声明年龄属性

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetName(){

returnname;

}

publicvoidsetAge(intage){

this.age=age;

}

publicintgetAge(){

returnage;

}

publicvoidtell(){

System.out.println("姓名:

"+name+",年龄:

"+age);

}

};

publicclasstext{

publicstaticvoidmain(Stringarsgh[]){

Personper=newPerson();//声明并实例化对象

per.setName("张三");//为name属性赋值

per.setAge(30);//为age属性赋值

per.tell();

}

};

newPerson(“张三”,30).tell();//匿名对象

publicStudent(Strings,Stringn,floatm,floate,floatc){

this.setStuno(s);

this.setName(n);

this.setMath(m);

this.setEnglish(e);

this.setComputer(c);

}、、构造方法

Studentstu=null;//声明对象

stu=newStudent("MLDN-33","李兴华",95.0f,89.0f,96.0f);//调用构造方法初始化对象

Stringname=newString("LiXingHua");//实例化String对象

System.out.println("姓名:

"+name);

Stringname="LiXingHua";//实例化String对象

System.out.println("姓名:

"+name);

两种方法,一般用直接赋值的方式。

这样可节省内存空间

Stringstr1="hello";//直接赋值

Stringstr2=newString("hello");//通过new赋值

Stringstr3=str2;//传递引用

System.out.println("str1==str2-->"+(str1==str2));//false

System.out.println("str1==str3-->"+(str1==str3));//false

System.out.println("str2==str3-->"+(str2==str3));//true

System.out.println("str1equalsstr2-->"+(str1.equals(str2)));//true

System.out.println("str1equalsstr3-->"+(str1.equals(str3)));//true

System.out.println("str2equalsstr3-->"+(str2.equals(str3)));//true

staticStringcountry="A城";//定义城市属性,有默认值,static

p1.country="B城";//修改static属性

publicstaticvoidsetCountry(Stringc){//此方法可以直接由类名称调用

country=c;

}

Person.setCountry("B城");//调用静态方法修改static属性的内容

classPerson{//定义Person类

privatestaticStringcountry="A城";//定义静态属性

privateStringname="Hello";

publicstaticvoidsFun(Stringc){

System.out.println("name="+name);//错误,不能调用非static属性

fun();//错误,不能调用非static方法

}

publicvoidfun(){

System.out.println("World");

}

};

classDemo{

{//直接在类中编写代码块,称为构造块

System.out.println("1、构造块。

");

}

static{//使用static,称为静态代码块

System.out.println("0、静态代码块");

}

publicDemo(){//定义构造方法

System.out.println("2、构造方法。

");

}

};

publicclasstext{

static{//在主方法所在的类中定义静态块

System.out.println("在主方法所在类中定义的代码块");

}

publicstaticvoidmain(Stringargs[]){

newDemo();//实例化对象

newDemo();//实例化对象

newDemo();//实例化对象

}

};结果:

0、静态代码块

1、构造块。

2、构造方法。

1、构造块。

2、构造方法。

1、构造块。

2、构造方法。

classSingleton{

privateSingleton(){//将构造方法进行了封装,私有化

}

publicvoidprint(){

System.out.println("HelloWorld!

!

!

");

}

};

publicclassSingletonDemo02{

publicstaticvoidmain(Stringargs[]){

Singletons1=null;//声明对象

s1=newSingleton();//错误,无法实例化对象

}

};

classSingleton{

privatestaticSingletoninstance=newSingleton();//在内部产生本类的实例化对象

publicstaticSingletongetInstance(){//通过静态方法取得instance对象

returninstance;

}

privateSingleton(){//将构造方法进行了封装,私有化

}

publicvoidprint(){

System.out.println("HelloWorld!

!

!

");

}

};

publicclassSingletonDemo05{

publicstaticvoidmain(Stringargs[]){

Singletons1=null;//声明对象

Singletons2=null;//声明对象

Singletons3=null;//声明对象

s1=Singleton.getInstance();//取得实例化对象

s2=Singleton.getInstance();//取得实例化对象

s3=Singleton.getInstance();//取得实例化对象

s1.print();//调用方法

s2.print();//调用方法

s3.print();//调用方法

}

};

//类名称数组名称[]=new类名称[长度]

Personper[]=newPerson[3];//开辟了三个空间大小的对象数组

Personper[]={newPerson("张三"),newPerson("李四"),newPerson("王五")};

classOuter{//定义外部类

privatestaticStringinfo="helloworld";//定义外部类的私有属性

staticclassInner{//使用static定义内部类为外部类

publicvoidprint(){//定义内部类的方法

System.out.println(info);//直接访问外部类的私有属性

}

};

publicvoidfun(){//定义外部类的方法

newInner().print();//通过内部类的实例化对象调用方法

}

};

publicclassInnerClassDemo03{

publicstaticvoidmain(Stringargs[]){

newOuter.Inner().print();//调用外部类的fun()方法

}

};

classOuter{//定义外部类

privateStringinfo="helloworld";//定义外部类的私有属性

classInner{//定义内部类

publicvoidprint(){//定义内部类的方法

System.out.println(info);//直接访问外部类的私有属性

}

};

publicvoidfun(){//定义外部类的方法

newInner().print();//通过内部类的实例化对象调用方法

}

};

publicclassInnerClassDemo04{

publicstaticvoidmain(Stringargs[]){

Outerout=newOuter();//外部类实例化对象

Outer.Innerin=out.newInner();//实例化内部类对象

in.print();//调用内部类的方法

}

};

classOuter{//定义外部类

privateStringinfo="helloworld";//定义外部类的私有属性

publicvoidfun(finalinttemp){//定义外部类的方法

classInner{//在方法中定义的内部类

publicvoidprint(){//定义内部类的方法

System.out.println("类中的属性:

"+info);//直接访问外部类的私有属性

System.out.println("方法中的参数:

"+temp);

}

};

newInner().print();//通过内部类的实例化对象调用方法

}

};

publicclasstext{

publicstaticvoidmain(Stringargs[]){

newOuter().fun(30);//调用外部类的方法

}

};

classA{

};

classB{

};

classCextendsA,B{//错误,同时继承了两个父类

};

interfaceA{//定义接口A

publicstaticfinalStringAUTHOR="李兴华";//全局常量

publicabstractvoidprint();//抽象方法

publicabstractStringgetInfo();//抽象方法

}

interfaceB{//定义接口B

publicvoidsay();//定义抽象方法

}

classXextendsBimplementsA{//X类线继承B类,再实现A接口

classA{//定义类A

publicvoidfun1(){//定义fun1()方法

System.out.println("A-->publicvoidfun1(){}");

}

publicvoidfun2(){

this.fun1();//调用fun1()方法

}

};

clas

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

当前位置:首页 > 法律文书 > 调解书

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

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