• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision2 (tree)
Time2013-11-12 08:52:08
Authorevakichi

Log Message

first add

Change Summary

Incremental Difference

--- java/src/math/Test.java (nonexistent)
+++ java/src/math/Test.java (revision 2)
@@ -0,0 +1,31 @@
1+/**
2+ *
3+ */
4+package math;
5+
6+/**
7+ * @author ishihara
8+ *
9+ */
10+public class Test {
11+
12+ /**
13+ * @param args
14+ */
15+ public static void main(String[] args) {
16+ // TODO 自動生成されたメソッド・スタブ
17+ Frac f1 = new Frac(-3);
18+ f1.printFrac();
19+ Frac f2 = new Frac(2,3);
20+ f2.printFrac();
21+ Frac f3 = Frac.plus(f1, f2);
22+ f3.printFrac();
23+ Frac f4 = Frac.minus(f1, f2);
24+ f4.printFrac();
25+ Frac f5 = Frac.mult(f1, f2);
26+ f5.printFrac();
27+ Frac f6 = Frac.div(f1, f2);
28+ f6.printFrac();
29+ }
30+
31+}
--- java/src/math/Tips.java (nonexistent)
+++ java/src/math/Tips.java (revision 2)
@@ -0,0 +1,23 @@
1+/**
2+ *
3+ */
4+package math;
5+
6+/**
7+ * @author ishihara
8+ *
9+ */
10+public class Tips {
11+ public static int Gcd(int n1,int n2)
12+ {
13+ int m=Math.max(Math.abs(n1), Math.abs(n2));
14+ int n=Math.min(Math.abs(n1), Math.abs(n2));
15+ if (n==0)
16+ return m;
17+ int l=m%n;
18+ if(l==0)
19+ return n;
20+ else
21+ return Tips.Gcd(l, n);
22+ }
23+}
--- java/src/math/Frac.java (nonexistent)
+++ java/src/math/Frac.java (revision 2)
@@ -0,0 +1,66 @@
1+/**
2+ *
3+ */
4+package math;
5+
6+/**
7+ * @author ishihara
8+ *
9+ */
10+public class Frac {
11+ private int numerator;
12+ private int denominator;
13+
14+ public Frac(int numerator)
15+ {
16+ this(numerator,1);
17+ }
18+
19+ public Frac(int numerator, int denominator)
20+ {
21+ this.numerator=numerator;
22+ this.denominator=denominator;
23+ reduction();
24+ }
25+
26+ public static Frac plus(Frac f1,Frac f2)
27+ {
28+ return new Frac(f1.getNumerator()*f2.getDenominator()+f1.getDenominator()*f2.getNumerator(),f1.getDenominator()*f2.getDenominator());
29+ }
30+
31+ public static Frac minus(Frac f1,Frac f2)
32+ {
33+ return new Frac(f1.getNumerator()*f2.getDenominator()-f1.getDenominator()*f2.getNumerator(),f1.getDenominator()*f2.getDenominator());
34+ }
35+
36+ public static Frac mult(Frac f1,Frac f2)
37+ {
38+ return new Frac(f1.getNumerator()*f2.getNumerator(),f1.getDenominator()*f2.getDenominator());
39+ }
40+
41+ public static Frac div(Frac f1,Frac f2)
42+ {
43+ return new Frac(f1.getNumerator()*f2.getDenominator(),f1.getDenominator()*f2.getNumerator());
44+ }
45+
46+ public int getNumerator(){return this.numerator;}
47+ public int getDenominator(){return this.denominator;}
48+
49+ public Frac getFrac(){return this;}
50+
51+ public void printFrac(){System.out.println(this.numerator+"/"+this.denominator);}
52+
53+ private void reduction()
54+ {
55+ int g = Tips.Gcd(this.numerator, this.denominator);
56+ try
57+ {
58+ this.numerator=this.numerator*(this.denominator/Math.abs(this.denominator))/g;
59+ this.denominator=this.denominator*(this.denominator/Math.abs(this.denominator))/g;
60+ }catch(ArithmeticException e)
61+ {
62+ System.out.println("DIV 0!!");
63+ }
64+ }
65+
66+}