public class Demo05 {
public static void main(String[] args) {
Triangle t1 = new Triangle(1,2,3);
System.out.println(t1);
Triangle t2 = new Triangle(2,2,3);
System.out.println(t2);
Triangle t3 = new Triangle(3,5,1);
System.out.println(t3);
Triangle t4 = new Triangle(3,4,5);
System.out.println(t4);
}
}
class Triangle {
float a, b, c;
public Triangle(float a, float b, float c) {
this.a = a;
this.b = b;
this.c = c;
}
public float zhouChang() {
//返回三角形的和
return a + b + c;
}
} else if (a == b || b == c || c == a) {
return "等腰三角形";
} else {
return "一般三角形";
}
对象数组、对象参数、可变参数。
*/
import java.util.Arrays;
public class Demo06 {
public static void main(String[] args) {
// 新建3个学生,把学生加入数组
Students s1 = new Students("Lily",50);
Students s2 = new Students("Lucy",55);
Students s3 = new Students("Tony",98);
Students[] ss = {s1,s2,s3};
System.out.println(Arrays.toString(ss));
modifyScore(ss);//调用静态方法,Demo06.modifyScore 类名.方法名 方式调用。同一个类中类名可以省略。
System.out.println(Arrays.toString(ss));
Students s4 = new Students("Jack",50);
System.out.println(s4);
modifyScore(s4);
System.out.println(s4);
Students s5 = new Students("Lily",50);
Students s6 = new Students("Lucy",55);
modifyScore1(s5,s6);
System.out.println(s5);
System.out.println(s6);
}
// 修改学生的分数,如果小于60,将分数提高到60分
public static void modifyScore(Students stu){
if(stu.score <60){
stu.score = 60;
}
}
// 批量修改学生的分数
public static void modifyScore(Students[] stu) {
for(Students s : stu){
if (s.score <60){
s.score = 60;
}
}
}
// 可变参数,当作一个数组来看,可以传入0个,1个,2 个....n个学生。
public static void modifyScore1(Students ...stu) {
for(Students s : stu){
if (s.score <60) {
s.score = 60;
}
}
}