📄 reward.java
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* How many grains of rice does the Rajah place on
* square n if the Rajah places one grain on
* the first square of a chessboard, and
* places double the amount of the previous
* square on the next square, and so on. Allow
* the user to repeat for different n.
*/
import iopack.Io;
public class Reward {
public static void main(String [] args) {
long amount;
char repeat;
int squarenum;
do {
amount = 1;
squarenum = Io.readInt("Which square, 1-64?");
if (squarenum == 1)
System.out.println("The reward on square 1 is 1");
else {
for (int i = 2; i <= squarenum; i++)
amount += amount;
System.out.print("The reward on square " + squarenum);
System.out.println(" is " + amount);
}
repeat = Io.readChar("Enter 'Y' to repeat, 'N' to quit");
} while (repeat == 'Y' || repeat == 'y');
Io.readString("Press any key to exit"); // Added for IDE use
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -