Skip to content

Instantly share code, notes, and snippets.

@kmizu
Last active December 16, 2019 05:31
Show Gist options
  • Save kmizu/45ce0dde3efc8d035b50a42766c196b6 to your computer and use it in GitHub Desktop.
Save kmizu/45ce0dde3efc8d035b50a42766c196b6 to your computer and use it in GitHub Desktop.
CCT社内勉強会用のものです
public class Fact {
public static int fact(int n) {
if(i < 0) throw new IllegalArgumentException("n must be >= 0");
int r = 1;
for(int i = 1; i <= n; i++) {
r *= i;
}
return r;
}
}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Compiled from "Fact.java"
public class Fact {
public Fact();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static int fact(int);
Code:
0: iload_0
1: ifge 14
4: new #2 // class java/lang/IllegalArgumentException
7: dup
8: ldc #3 // String n must be >= 0
10: invokespecial #4 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
13: athrow
14: iconst_1
15: istore_1
16: iconst_1
17: istore_2
18: iload_2
19: iload_0
20: if_icmpgt 33
23: iload_1
24: iload_2
25: imul
26: istore_1
27: iinc 2, 1
30: goto 18
33: iload_1
34: ireturn
public static void main(java.lang.String[]);
Code:
0: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
3: iconst_5
4: invokestatic #6 // Method fact:(I)I
7: invokevirtual #7 // Method java/io/PrintStream.println:(I)V
10: return
}
@kmizu
Copy link
Author

kmizu commented Dec 16, 2019

Compiled from "Fact.java"
public class Fact {
public Fact();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return

public static int fact(int);
Code:
0: iload_0
1: ifge 14
4: new #2 // class java/lang/IllegalArgumentException
7: dup
8: ldc #3 // String n must be >= 0
10: invokespecial #4 // Method java/lang/IllegalArgumentException."":(Ljava/lang/String;)V
13: athrow
14: iconst_1
15: istore_1
16: iconst_1
17: istore_2
18: iload_2
19: iload_0
20: if_icmpgt 33
23: iload_1
24: iload_2
25: imul
26: istore_1
27: iinc 2, 1
30: goto 18
33: iload_1
34: ireturn

public static void main(java.lang.String[]);
Code:
0: getstatic #5 // Field java/lang/System.out:Ljava/io/PrintStream;
3: iconst_5
4: invokestatic #6 // Method fact:(I)I
7: invokevirtual #7 // Method java/io/PrintStream.println:(I)V
10: return
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment