Skip to content

Instantly share code, notes, and snippets.

@nhojpatrick
Created November 15, 2013 11:08
Show Gist options
  • Save nhojpatrick/7482733 to your computer and use it in GitHub Desktop.
Save nhojpatrick/7482733 to your computer and use it in GitHub Desktop.
if without brackets testing else
$ diff IfElseNoBrackets.p IfNoBrackets.p
1,3c1,3
< Compiled from "IfElseNoBrackets.java"
< public class IfElseNoBrackets {
< public IfElseNoBrackets();
---
> Compiled from "IfNoBrackets.java"
> public class IfNoBrackets {
> public IfNoBrackets();
$
public class IfElseNoBrackets {
public static void main(String[] args) {
System.out.println(test(10));
}
public static String test(int a) {
if(a%2 == 0)
return "even";
else
return "odd";
}
}
Compiled from "IfElseNoBrackets.java"
public class IfElseNoBrackets {
public IfElseNoBrackets();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: bipush 10
5: invokestatic #3 // Method test:(I)Ljava/lang/String;
8: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
11: return
public static java.lang.String test(int);
Code:
0: iload_0
1: iconst_2
2: irem
3: ifne 9
6: ldc #5 // String even
8: areturn
9: ldc #6 // String odd
11: areturn
}
public class IfNoBrackets {
public static void main(String[] args) {
System.out.println(test(10));
}
public static String test(int a) {
if(a%2 == 0)
return "even";
return "odd";
}
}
Compiled from "IfNoBrackets.java"
public class IfNoBrackets {
public IfNoBrackets();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: bipush 10
5: invokestatic #3 // Method test:(I)Ljava/lang/String;
8: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
11: return
public static java.lang.String test(int);
Code:
0: iload_0
1: iconst_2
2: irem
3: ifne 9
6: ldc #5 // String even
8: areturn
9: ldc #6 // String odd
11: areturn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment