ForNext
Only Do What Only You Can Do
119. constructor
Hyperpolyglot C++ Style Languages: C++, Objective C, Java, C# より (2012.05.08)
VBScript
JScript
Perl
PHP
Python
Ruby
PowerShell
Scala
F#
C
C++
Rational::Rational(int n, int d) : num(n), denom(d) { if (denom == 0) { throw "zero denominator"; } int div = gcd(n,d); num = num / div; denom = denom / div; }
C++Builder
VC++
C#
public Rational(int n, int d) { if (0 == d) { throw new System.Exception("zero denominator"); } if (d < 0) { this.num = -1 * n; this.denom = -1 * d; } else { this.num = n; this.denom = d; } }
Java
public Rational(int n, int d) throws Exception { if (d == 0) { throw new Exception("zero denominator"); } if ( d < 0 ) { this.num = -1 * n; this.denom = -1 * d; } else { this.num = n; this.denom = d; } }
Objective-C
-(Rational*) initWith: (int) n: (int) d { self = [super init]; if (self) { self.num = n; self.denom = d; } return self; }