-
-
Save gaoyike/4f12a0a7731c09c6da96 to your computer and use it in GitHub Desktop.
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
package Basic; | |
import java.util.Arrays; | |
/** | |
* Created by chenguanghe on 9/29/14. | |
*/ | |
public class DistictProducts { | |
public static int products(int n) { | |
boolean[] test = new boolean[n*n+1]; | |
Arrays.fill(test, false); | |
for (int i = 1; i <= n; i++) { | |
for (int j = 1; j <= n; j++) { | |
test[i*j] = true; | |
} | |
} | |
int count = 0; | |
for (boolean b : test){ | |
if(b) | |
count++; | |
} | |
return count; | |
} | |
public static void main(String[] args) { | |
for (int i = 1; i <=10 ; i++) { | |
System.out.print(products(i)+", "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment