package com.hanqi.kejian; public class lianxi0918 { //第一题比较输出最大的一个数 // 方法 public int max(int a, int b) { if (a < b) { return b; } else { return a; } // return () } public double max(double a, double b) { if (a < b) { return b; } else { return a; } } public double max(double a, double b, double c) { return max(max(a, b), c); } // 第二题.创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它。 // 成员变量 private double a; private double b; private double c; private double zhouChang; //获得getter和setter public double getA() { return a; } public void setA(double a) { this.a = a; } public double getB() { return b; } public void setB(double b) { this.b = b; } public double getC() { return c; } public void setC(double c) { this.c = c; } public double getZhouChang() { return zhouChang; } public void setZhouChang(double zhouChang) { this.zhouChang = zhouChang; } public void getbian(double a,double b,double c) { this.a=a; this.b=b; this.c=c; } public double ZC() { this.zhouChang=a+b+c; return zhouChang; } } //主类main方法 package com.hanqi.kejian; public class lianxitext0918 { public static void main(String[] args) { // TODO Auto-generated method stub lianxi0918 ss=new lianxi0918(); System.out.println(ss.max(1, 2));//比较double型的ab输出大的 System.out.println(ss.max(3, 4));//比较int型的ab输出大的 System.out.println(ss.max(5, 6, 7));//比较double型的abc输出大的 //三角形 lianxi0918 A=new lianxi0918(); A.getbian(1, 2, 3); System.out.println(A.ZC()); } }
运行结果: