Basic-benchmark-experiment/Java/code_cycle.java

21 lines
665 B
Java
Raw Normal View History

2024-03-11 12:43:52 +02:00
public class code_cycle {
public static void main(String[] args) {
int total_attempts = 256*256*256;
int successful_attempts = 0;
for (int a = 0; a < 256; a++) {
for (int b = 0; b < 256; b++) {
for (int c = 0; c < 256; c++) {
if (a + b + c > 300) {
successful_attempts++;
}
}
}
}
System.out.println("Iterations: " + total_attempts);
System.out.println("Valid sums: " + successful_attempts);
System.out.println("Probability: " + (float) successful_attempts / total_attempts);
}
}