a simple subject I usually do not.
When the location area at most six lowest is -6 movement can be any number. Must be in a range of areas
such location is the location of a mobile two becomes three up . If the position is moved two positions 5 or 5 as the area is 6 to go back up to how to solve this ?
public int movePosition () {
if (position> = 6) {
position = 6;
velocity = velocity * -1;
}
else if (position <= -6) {
position = -6;
velocity = velocity * -1;
}
position = position + velocity;
return position;
}
this does not resolve the five mobile 2 becomes five case please help
------ Solution ------------ --------------------------------
If you do not know how to write back and forth direction , and then open a stickers, I can help you write
------ For reference only -------------------------------- -------
the college textbook turned out good refresher modulo
------ For reference only ----------------------------- ----------
forget, or give you paste a code, you gave me the points
public static void main(String[] args) {
int m = 6; //模 为6
System.out.println( 2 % m);
System.out.println( 3 % m);
System.out.println( 4 % m);
System.out.println( 5 % m);
System.out.println( 6 % m);
System.out.println( 7 % m);
System.out.println( 8 % m);
System.out.println( 9 % m);
}
------ For reference only ----------------------------------- ----
Thanks for your advice
Your suggestion is not what I want. . I mean to say
6 and n- 6 on both sides
-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6
If you are in a position to go eight two -step or return to the 2 position is the order of 34,565 ; 432 eight -step . .
------ For reference only -------------------------------------- -
package test.model;
public class TestModel {
// 往正方向移动的方法
public static int move(int p, int step) {
if ((p + step) > 6) {
p = 6 - (p + step) % 6;// 看清楚了,用模运算
} else {
p = p + step;
}
return p;
}
public static void main(String[] args) {
System.out.println(move(2, 8));
}
}
look at, and hastened to sub it
------ For reference Thank you, my brothers and only ---------------------------------------
how to give you points I was a novice
is not useful to me can
------ For reference only --------------------------- ------------
brothers last question . . Go to step 17 if the position of step I is in the range 1 -6 to 6
-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6
should be 2 3456543210-1-2 -3 -5 -6 -5 17 step position should be that way at -5 you can not set up this problem. . But please tell me how I added extra points you points. . . Thank you very much
------ For reference only -------------------------------- -------
I think it is better to use MAP collection to solve this problem
------ For reference only ---------------- -----------------------
You do not point " reference " I can not see the contents of your reply .
you say is a problem, I designed this program is not robust , and I think again
没有评论:
发表评论