Created
January 21, 2013 20:00
-
-
Save woodie/4588810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyMath | |
def factoral(n:int); returns int | |
if n == 0 | |
return 1 | |
elsif n > 0 | |
return factoral(n - 1) * n | |
else n < 0 | |
raise("Sorry, no negative numbers please") | |
return 0 | |
end | |
end | |
end | |
mm = MyMath.new | |
puts "" | |
puts "factoral of 5 if #{mm.factoral(5)}" | |
puts "factoral of -5 if #{mm.factoral(-5)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated from my_math.mirah | |
public class MyMath extends java.lang.Object { | |
public static void main(java.lang.String[] argv) { | |
MyMath mm = null; | |
mm = new MyMath(); | |
java.io.PrintStream temp$1 = java.lang.System.out; | |
temp$1.println(""); | |
java.io.PrintStream temp$2 = java.lang.System.out; | |
temp$2.println("factoral of 5 if " + mm.factoral(5)); | |
java.io.PrintStream temp$3 = java.lang.System.out; | |
temp$3.println("factoral of -5 if " + mm.factoral(-5)); | |
} | |
public int factoral(int n) { | |
if ((n == 0)) { | |
return 1; | |
} | |
else { | |
if ((n > 0)) { | |
return (this.factoral((n - 1)) * n); | |
} | |
else { | |
(n < 0); | |
throw new java.lang.RuntimeException("Sorry, no negative numbers please"); | |
return 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment