printSlam(x) =
print("Sla" + x `times` "m")
Input | Output |
---|---|
1 | Slam |
2 | Slamm |
3 | Slammm |
4 | Slammmm |
public static void printSlam(int);
Code:
0: getstatic #2
3: ldc #3
5: invokevirtual #4
8: iconst_0
9: istore_1
10: iload_1
11: iload_0
12: if_icmpge 29
15: getstatic #2
18: ldc #5
20: invokevirtual #4
23: iinc 1, 1
26: goto 10
29: return
public static void printSlam(int n){
System.out.print("Sla");
int i = 0;
while(i < n){
System.out.print("m");
i = i + 1;
}
}
printSlam(x) =
print("Sla" + x `times` "m")
printSlam(x) =
print("Sla" + x `times` "m")
1 2 3 4 5 6
Ingmar Dasseville - Science Slam 2016