I'm fairly new to java and I'm having trouble figuring out how to do this equation using "for loops" anyone on here help/post solution?
A chess board has 64 squares. Suppose you were to put one cent on the first square, then 2 cents on the second, then 4 cents on the third, then 8 cents on the fourth , until all the squares were covered.
Using a "for loop", create a program to answer the following questions q1 What would be the amount placed on the 64th square ?
q2 What would be the total amount placed on the board ?
You don't really need to imagine a chess board for this. It's just used for the arbitrary limit of 64 tiles. You basically need to find the function defined by the sequence f(1) = 1, f(2) = 2, f(3) = 4, f(4) = 8, ... and then use that function to find f(x = 64) for the first question and then to find f(1) + f(2) + ... + f(63) + f(64) for the second question.
What your teacher has forgotten is that you cannot fit such large numbers into an int nor into a long. You will have to use BigInteger. It has a pow(int) method which you will find useful. Don't writeWriteThat has to do with BigInteger being immutable. AB is correct that you can do the exercise without a loop.