JAVA_2Lesson

时间:2022-04-04 22:09:32

package test;

public class abc {

public static void main(String[] arg)

{

int[][] xx=new int[3][];

xx[0]=new int[3];

xx[1]=new int[2];

xx[2]=new int[1];

for(int i=0;i<xx.length;++i)

for(int j=0;j<xx[i].length;++j)

xx[i][j]=j;

for(int[] i1:xx)

for(int j:i1)

System.out.println(j);

System.out.println(">>>>>>>>>>>");

int [][] x={{1,2,3},{1,2},{1}};

System.out.println(x[1][1]);

}

}

package test2_class;

public class student {

String sName;

String sNumber;

int sage;

public String getsName() {

return sName;

}

public void setsName(String sName) {

this.sName = sName;

}

public String getsNumber() {

return sNumber;

}

public void setsNumber(String sNumber) {

this.sNumber = sNumber;

}

public int getSage() {

return sage;

}

public void setSage(int sage) {

this.sage = sage;

}

void eat()

{

System.out.println(sName+" have lunch");

}

void sleep()

{

System.out.println(sName+" sleep");

}

public boolean equals(Object obj)

{

student s=(student)obj;

if(sName==s.sName&&sage==s.sage&&sNumber==s.sName)

{

return true;

}

return false;

}

public String toString()

{

return "name:"+sName+"\t"+"age:"+sage+"\t"+"number:"+sNumber;

}

}

package test2_class;

public class Main {

public static void main(String[] args)

{

student t=new student();

t.setsName("zhangsan");

t.setSage(15);

t.setsNumber("2678");

System.out.println(t.getSage());

System.out.println(t.getSage());

System.out.println(t.getSage());

t.eat();

t.sleep();

if(t.equals(t))

System.out.println("equal");

System.out.println(t);

}

}

package string_practice;

public class string_practice {

public static void main(String[] args) {

// TODO Auto-generated method stub

String str3="HELLO";

String str4="HELLO";

String str1=new String("HELLO");

String str2=new String("HELLO");

if(str3==str4)

{

System.out.println("equals");

}

if(str1.equals(str2))

{

System.out.println("equals");

}

Integer a = new Integer(1);

}

}

类方法中不能访问非static变量.

导入的两个包有相同名的类,则不导入

final定义常量的关键

相关文章