anotherCha
This commit is contained in:
+22
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user