Skip to content

Instantly share code, notes, and snippets.

@woodie
Created January 21, 2013 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodie/4588810 to your computer and use it in GitHub Desktop.
Save woodie/4588810 to your computer and use it in GitHub Desktop.
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)}"
// 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