Created
July 25, 2018 10:58
-
-
Save burakozhan/c57644ad34bd0960376e158f3132f492 to your computer and use it in GitHub Desktop.
Side effects of bitwiseAND vs logicalAND
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
import org.junit.Test; | |
public class BooleanTest { | |
private static boolean D = true; | |
@Test | |
public void bitwiseAND() { | |
int finds = 0; | |
int ctr = 0; | |
for (int i = 0; i < 100; i++){ | |
if (i % 7 == 0 & ctr++ % 7 == 0){ | |
if(D) System.out.printf("i = %d , ctr = %d", i, ctr); | |
if(D) System.out.print("\nfound one"); | |
finds++; | |
if(D) System.out.println(); | |
} | |
} | |
System.out.printf("\nFound total items %d", finds); | |
System.out.printf("\nFinal counter position %d", ctr); | |
System.out.print("\n\n"); | |
} | |
@Test | |
public void logicalAND() { | |
int finds = 0; | |
int ctr = 0; | |
for (int i = 0; i < 100; i++){ | |
if (i % 2 == 0 && ctr++ % 7 == 0){ | |
if(D) System.out.printf("i = %d , ctr = %d", i, ctr); | |
if(D) System.out.print("\nfound one !"); | |
finds++; | |
if(D) System.out.println(); | |
} | |
} | |
System.out.printf("\nFound total items %d", finds); | |
System.out.printf("\nFinal counter position %d", ctr); | |
System.out.print("\n\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment