Mars Lander Medium variables issue

Hello again to all who read this.

This time i want somebody explain what happends here. I have to err printstream to show the X and Y variables, just after the declaration into the while loop ( then, there is nothing what can change the variables between).

The last time i post, i have a “stupid” ( yes, me to myselve :stuck_out_tongue:) mistake with err and out disorder. This time is different. This time i pass the first test, and the X and Y shows the variables that i hope.

The second test dont pass, and one of the problems is the X and Y shows the fuel and the angle. As i said, there is nothing between the declaration and the err output, then i need explanations.

I have screenshot that proove that i state here, but i cannot upload it either to the post.

If you can give me some advice, it will be welcome.

Pablo González

Don’t break the loop to find the platform maybe.

Everytime you don’t understand your debug output: Make it more verbose and add debug output to make sure that what you think is happening is really happening.

Thanks @SaiksyApo and @chrm, here more info (copied and pasted)

Landing in progress…
X=2501m, Y=2695m, HSpeed=1m/s VSpeed=-5m/s
Fuel=547l, Angle=-16°, Power=2 (2.0m/s2)
Standard Error Stream:
X: 2501
Y: 2695
hSpeed: 1
vSpeed: -5
fuel: 547
rotate: -16
power: 2

This is for first test. As you see, the output is exactly as the variables avobe.

Landing in progress…
X=6194m, Y=2787m, HSpeed=-105m/s VSpeed=-8m/s
Fuel=594l, Angle=45°, Power=3 (3.0m/s2)
Standard Error Stream:
X: 599
Y: 75
hSpeed: 1
vSpeed: 6298
fuel: 2793
rotate: -103
power: -6

This is for the second test. I copied as is, without changin any part of the code.

Landing in progress…
X=6410m, Y=2798m, HSpeed=-91m/s VSpeed=-3m/s
Fuel=749l, Angle=75°, Power=1 (1.0m/s2)
Standard Error Stream:
X: 6410
Y: 2798
hSpeed: -91
vSpeed: -3
fuel: 749
rotate: 75
power: 1

third test, it is ok…

Landing in progress…
X=600m, Y=2698m, HSpeed=101m/s VSpeed=-3m/s
Fuel=799l, Angle=-75°, Power=1 (1.0m/s2)
Standard Error Stream:
X: -90
Y: 0
hSpeed: 600
vSpeed: 2698
fuel: 101
rotate: -3
power: 799

fourth test, again ( power 799??)

Landing in progress…
X=6344m, Y=2687m, HSpeed=-55m/s VSpeed=-8m/s
Fuel=994l, Angle=45°, Power=3 (3.0m/s2)
Standard Error Stream:
X: 6398
Y: 2693
hSpeed: -53
vSpeed: -6
fuel: 997
rotate: 60
power: 2

fifth and last, this seems ok also.

while (true) {
int X = in.nextInt();
int Y = in.nextInt();
int hSpeed = in.nextInt(); // the horizontal speed (in m/s), can be negative.
int vSpeed = in.nextInt(); // the vertical speed (in m/s), can be negative.
int fuel = in.nextInt(); // the quantity of remaining fuel in liters.
int rotate = in.nextInt(); // the rotation angle in degrees (-90 to 90).
int power = in.nextInt(); // the thrust power (0 to 4).

        System.err.println("X: "+X);
        System.err.println("Y: "+Y);
        System.err.println("hSpeed: "+hSpeed);
        System.err.println("vSpeed: "+vSpeed);
        System.err.println("fuel: "+fuel);
        System.err.println("rotate: "+rotate);
        System.err.println("power: "+power);

And, as said before, the debug lines are below the variables declaration

Now, can you, with all patience, explain me what can be the problem here? (I hope this is enough verbose :wink:

When I load the default provided code and add your “err” lines, everything is ok.

1 Like

I believe you, because it must be ok. As you see, if there is nothing between the declaration and the “err” lines, nothing in my “not-default” code can change that, but it changes.

@yohannjardin, can i bother you?

This is your for loop to read landX and landY. I simplify the code to keep it short.

        for (int i = 0; i < surfaceN; i++) {
            int landX = in.nextInt(); // X coordinate of a surface point. (0 to 6999)
            int landY = in.nextInt(); // Y coordinate of a surface point. By linking all the points together in a sequential fashion, you form the surface of Mars.

            [SOMETHING CONTAINING "Break;"]


Your break instruction is getting you out of the loop. You do not read all the landX and landY variables, but they are still in the standard input stream. Then you enter the while loop, read the input corresponding to landX and landY thinking they represent variables given in the template.

Consider the input as something stupid that will always follow what the statement announce it will, no matter what happens, and that it will not care about what you do in your code.

1 Like

@clear as always, @yohannjardin. There is some “Input looser achievement”? :smile: It will be giving me bad reputation. Thanks a lot

You’re welcome.

By the way, think about posting in the topic already existing for that puzzle. (In the IDE, you have a “I need help” button on the top right corner that redirect to the topic corresponding to that puzzle.)
This makes our work easier :wink:

I guess “Don’t break the loop to find the platform maybe.” was not clear enougth :frowning: