在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
import java.util.Scanner; public class test{ public static void main(String args[]){ Rational a=new Rational(4,5); Rational b=new Rational(3,2); Rational c=a.chu(b); c.show(); } } class Rational{ int fenzi=1; int fenmu=1; int f(int a,int b){//公约数 if(b>a){ int c=a; a=b; b=c; } // System.out.println(a); int c=a%b; for(;c!=0;c=a%b){ a=b; b=c; } return b; } Rational(int a,int b){ int c=f(Math.abs(a),Math.abs(b)); fenzi=a/c; fenmu=b/c; System.out.println(c); } Rational jia(Rational r){ int a=fenzi*r.fenmu+r.fenzi*fenmu; int b=fenmu*r.fenmu; // System.out.println(b); Rational c=new Rational(a,b); return c; } Rational jian(Rational r){ int a=fenzi*r.fenmu-r.fenzi*fenmu; int b=fenmu*r.fenmu; // System.out.println(b); Rational c=new Rational(a,b); return c; } Rational cheng(Rational r){ int a=fenzi*r.fenzi; int b=fenmu*r.fenmu; Rational c=new Rational(a,b); return c; } Rational chu(Rational r){ int a=fenzi*r.fenmu; int b=fenmu*r.fenzi; Rational c=new Rational(a,b); return c; } void show(){ System.out.println(fenzi+"/"+fenmu); } }
import java.util.Scanner; public class test{ public static void main(String args[]){ Line a=new Line(); a.work(); } } class Input{ Del b; Input(Del a){ b=a; } void work(){ System.out.println("多少个评委"); Scanner in=new Scanner(System.in); int num=in.nextInt(); System.out.println("分别给了多少分"); double a[]=new double[num]; for(int i=0;i<num;i++){ a[i]=in.nextDouble(); } b.del(a); } } class Del{ Count b; Del(Count a){ b=a; } void del(double a[]){ java.util.Arrays.sort(a); double b[]=new double[a.length-2]; for(int i=1;i<=b.length;i++){ b[i-1]=a[i]; } this.b.count(b); } } class Count{ void count(double a[]){ double num=0; // for(int i=0;i<a.length;i++){ // System.out.println(a[i]); // } for(int i=0;i<a.length;i++){ num+=a[i]; } double c=num/a.length; System.out.println(c); } } class Line{ Input a; Del b; Count c; Line(){ c=new Count(); b=new Del(c); a=new Input(b); } void work(){ a.work(); } }
|
请发表评论