代码拉取完成,页面将自动刷新
package test_01;
public class test_04_05 {
/* public class Fraction {
private int fenZi;
private int fenMu;
public Fraction() {
}
public Fraction(int fenZi, int fenMu) {
super();
this.fenZi = fenZi;
this.fenMu = fenMu;
}
public int getFenZi() {
return fenZi;
}
public void setFenZi(int fz) {
this.fenZi = fz;
}
public int getFenMu() {
return fenMu;
}
public void setFenMu(int fm) {
this.fenMu = fm;
}
public void huaJian() {
if (fenZi == 0) {
fenMu = 1;
}
int yueshu = getYueshu();
if (fenMu > 0) {
fenZi /= yueshu;
fenMu /= yueshu;
} else {
fenZi /= -yueshu;
fenMu /= -yueshu;
}
}
private int getYueshu() {
int a = Math.abs(fenZi);
int b = Math.abs(fenMu);
int smaller = Math.min(a, b);
for (int i = smaller; i > 1; i--) {
if (a % i == 0 && b % i == 0) {
return i;
}
}
return 1;
}
public String toString() {
if (fenMu == 1) {
return fenZi + "";
}
return fenZi + "/" + fenMu;
}
public void jia(Fraction a) {
this.fenZi = this.fenZi * a.getFenMu() + a.getFenZi() * this.fenMu;
this.fenMu = this.fenMu * a.getFenMu();
}
public void jian(Fraction a) {
this.fenZi = this.fenZi * a.getFenMu() - a.getFenZi() * this.fenMu;
this.fenMu = this.fenMu * a.getFenMu();
}
}
*/
/* Scanner sc = new Scanner(System.in);
ArrayList<MixedFraction> list = new ArrayList<>();
Collections.addAll(list, new MixedFraction(sc.next()), new MixedFraction(sc.next()), new MixedFraction(sc.next()), new MixedFraction(sc.next()), new MixedFraction(sc.next()), new MixedFraction(sc.next()));
for (MixedFraction num : list) {
System.out.print(num + " ");
}
System.out.println();
Collections.reverse(list);
for (MixedFraction num : list) {
System.out.print(num + " ");
}
System.out.println();
HashSet<MixedFraction> hashSet = new HashSet<>(list);
System.out.println(list.size() - hashSet.size() + 1);
TreeSet<MixedFraction> treeSet = new TreeSet<>(list);
for (MixedFraction num : treeSet) {
System.out.print(num + " ");
}
System.out.println();
MixedFraction maxMixedFraction = new MixedFraction("0");
MixedFraction target = new MixedFraction("4[1/3]");
for (MixedFraction num : treeSet) {
if (num.compareTo(target) <= 0) {
if (num.compareTo(maxMixedFraction) >= 0) maxMixedFraction = num;
}
}
System.out.print(maxMixedFraction + " ");
}
class MixedFraction extends Fraction implements Comparable<MixedFraction> {
private int zengShu;
public int getZengShu() {
return zengShu;
}
public void setZengShu(int zengShu) {
this.zengShu = zengShu;
}
public String toString() {
return getZengShu() + "[" + super.toString() + "]";
}
public MixedFraction(String text) {
Pattern pattern = Pattern.compile("\\d+|-\\d+");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
if (this.zengShu == 0) {
setZengShu(Integer.parseInt(matcher.group()));
} else if (this.getFenZi() == 0) {
setFenZi(Integer.parseInt(matcher.group()));
} else if (this.getFenMu() == 0) {
setFenMu(Integer.parseInt(matcher.group()));
}
}
}
public int compareTo(MixedFraction o) {
return (int) ((double) ((this.getZengShu() * this.getFenMu()) + this.getFenZi()) / this.getFenMu() - (double) ((o.getZengShu() * o.getFenMu()) + o.getFenZi()) / o.getFenMu());
}
public int hashCode() {
int result = Integer.toString(getZengShu()).hashCode();
result = 17 * result + Integer.toString(getFenZi()).hashCode();
result = 17 * result + Integer.toString(getFenMu()).hashCode();
return result;
}
public boolean equals(Object obj) {
if (!(obj instanceof MixedFraction)) {
return false;
}
MixedFraction MixedObj = (MixedFraction) obj;
if (this == MixedObj) {
return true;
}
return MixedObj.zengShu == this.zengShu && MixedObj.getFenZi() == this.getFenZi() && MixedObj.getFenMu() == this.getFenMu();
}
*/
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。