codeChallenge/Grains.java
2024-09-21 12:04:52 -04:00

23 lines
470 B
Java

/**
* 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;
}
}