第一组代码:
1、
package q;
public class B {
public static void main(String[] agrs) {
int[] array= {5,15,25,500,20,100};
int max =B2.getMax(array);
System.out.println("最大值:" + max);
}
}
2、
package q;
public class B2 {
public static int getMax(int[] array) {
int max =array[0];
for (int i=1;i< array.length;i++) {
if (array[i]>max) {
max =array[i];
}
}
return max;
}
}
第二组代码:
1、
package q;
public class C {
public static void main(String[] agrs) {
C2 AC1=new C2();
AC1.setAge(19);
AC1.setName("周洪");
AC1.show();
System.out.println("============");
C2 AC2=new C2();
AC2.setAge(19);
AC2.setName("无尘");
AC2.show();
AC2.show();
}
}
2、
package q;
public class C2 {
private String name;
private double age;
private boolean male;
public void setMale(boolean boy) {
male=boy;
}
public boolean isMale() {
return male;
}
public void setAge(double num) {
if (num <200 && num>=0) {
age = num;
} else {
System.out.println("数据不合理");
}
}
public double getAge() {
return age;
}
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void show() {
System.out.println("我是"+ name + "年龄" + age);
}
}
第三组代码:
1、
package q;
public class D {
private String name;
private double age;
private boolean male;
public void setMale(boolean boy) {
male=boy;
}
public boolean isMale() {
return male;
}
public void setAge(double num) {
if (num <200 && num>=0) {
age = num;
} else {
System.out.println("数据不合理");
}
}
public double getAge() {
return age;
}
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void show() {
System.out.println("我是"+ name + "年龄" + age);
}
}
2、
package q;
public class D2 {
public static void main(String[] agrs) {
D D=new D();
D.setAge(22);
D.setName("无尘");
D.setMale(false);
D.show();
if (D.isMale()==true);
{
System.out.append("男");
}
{
System.out.append("女");
}
}
}