Created
November 15, 2013 11:08
-
-
Save nhojpatrick/7482733 to your computer and use it in GitHub Desktop.
if without brackets testing else
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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(); | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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