codegen: handle exceptions of a method
[mate.git] / tests / Fac.java
1 package tests;
2
3 public class Fac {
4         public static void main(String args[]) {
5                 int sum = 0;
6                 for (int i = 0; i < 10; i++) {
7                         sum += fac(i);
8                 }
9                 System.out.printf("result: 0x%08x\n", sum);
10                 // System.out.printf("result: 0x%08x\n", facFor(0x10));
11         }
12
13         public static int fac(int a) {
14                 int b = 1;
15                 while (a > 0) {
16                         b *= a;
17                         a--;
18                 }
19                 return b;
20         }
21
22         public static int facFor(int n) {
23                 int p = 1;
24                 for(int i = 1; i <= n; i++) {
25                         p *= i;
26                 }
27                 return p;
28         }
29 }