JAVA 面向对象 入门编程
输入三个数,将这三个数由小到大,由大到小排序。
给定 r,h,求圆的面积,周长及以该园为底的圆柱体体积
public class Paixu {//排序类
private double a,b,c;
Paixu(){} //构造方法
public void seta(double a){
this.a=a;
}
public void geta() {
this.a=a;
}
public void setb(double b){
this.b=b;
}
public void getb(){
this.b=b;
}
public void setc(double c){
this.c=c;
}
public void getc(){
this.c=c;
}
public void paixu(double a,double b,double c) { //从小到大排序的方法
double t;
if(a>b) {
t=a;
a=b;
b=t;
}
if(a>c) {
t=a;
a=c;
c=t;
}
if(b>c) {
t=b;
b=c;
c=t;
}
System.out.println("由小到大排序为"+" "+a+" "+b+" "+c);
}
public void paixu2(double a,double b,double c) { //从大到小排序的方法
double t;
if(a<b) {
t=a;
a=b;
b=t;
}
if(a<c) {
t=a;
a=c;
c=t;
}
if(b<c) {
t=b;
b=c;
c=t;
}
System.out.println("由大到小排序为"+" "+a+" "+b+" "+c);
}
}
public interface Jiekou {//创建接口(关键字)
double pi=3.14;//接口只能定义常量
public void mianji(double r);
public void zhouchang(double r);
}
public class Circle implements Jiekou{//实现接口(关键字)
double r;
Circle (double r){
this.r=r;
}
public void mianji(double r) {
System.out.println("圆的面积是"+pi*r*r);
}
public void mianji(double r,double h) {//方法的重载
System.out.println("圆zhu的ti积是"+pi*r*r*h);
}
public void zhouchang(double r) {
System.out.println("圆的周长是"+pi*r*2);
}
}
import java.util.Scanner; //导入键盘输入包
public class Text {
public static void main(String [] args) {
Circle ci =new Circle (3);
ci.mianji(3);
ci.zhouchang(3);
ci.mianji(3, 6);
Scanner sc = new Scanner(System.in); //创建输入对象
double a,b,c;
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
Paixu p= new Paixu();
p.seta(a);
p.setb(b);
p.setc(c);
p.paixu(a, b, c);
p.paixu2(a, b, c);
}
}