anotherCha

This commit is contained in:
2024-09-21 12:03:25 -04:00
parent f384067ac0
commit a66ffc8910
9 changed files with 90 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
/**
* Grains
*/
public class Grains {
public static void main(String[] args) {
System.out.println(grainsCount());
}
public static double grainsCount() {
// Calculate the number of grains of wheat on a chessboard given that the number
// on each square doubles.
double gCount = 0;
double grainOnCurrentSQ = 1;
for (int i = 1; i <= 64; i++) {
gCount += grainOnCurrentSQ;
grainOnCurrentSQ *= 2;
}
return gCount;
}
}