Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 AP 快速参考代码中,它声明“公共setDirection(int newDirection)将此演员的方向设置为 0 到 359 度之间的角度,相当于 newDirection”
setDirection(int newDirection)
但是,在发布的考试选择题之一中,它指出您可以通过调用来设置方向setDirection(getDirection + RIGHT);,但是,如果角度变得大于或等于 360 度怎么办?一个例子是 390 度。
setDirection(getDirection + RIGHT);
这会产生运行时错误,还是会%360产生正确的参考角度?
%360
我已经找到了我的问题的答案。在编译 GridWorld 案例研究后,我可以确认任何整数值(只要它是有效整数)都可以在该setDirection(new Location);方法中工作。
setDirection(new Location);