Kann jemand bitte den Code für den Java hamster simulator testen | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Kann jemand bitte den Code für den Java hamster simulator testen

Hallo ich habe einen Code für den Java hamster simulator geschrieben da ich ihn zurzeit nicht testen kann wollte ich fragen ob ihn jemand testen kann und mir schreiben kann ob er funktioniert und was man besser machen kann der Code ist für ein Labyrinth er sollte auf jedes Labyrinth anwendbar sein dies ist der Code void main { do { Code(); } } void recht() { linksUm(); linksUm(); linksUm(); } void Code() { recht(); if (vornFrei()) vor(); else if (!vornFrei() && vornFrei()) linksUm(); vor(); else if (!vornFrei() && vornFrei()) linksUm(); vor(); }

25th Nov 2022, 7:12 PM
fff ggg
fff ggg - avatar
2 Answers
0
1. It is not valid Java syntax. Missing parentheses and args from main function signature, and it is not clear what all the other functions do which you are trying to call. There is no "do" statement in Java. 2. The code is badly structured. Use indentation to make it more readable. 3. When you want to execute multiple statements in the "if", you have to enclose the block in braces. 4. Logical error: if (!vornFrei() && vornFrei()) can never be true, you are checking if something is true and false at the same time. Possibly if the vornFrei function has some side effect, this may be different, but from the code you provided, I cannot tell.
26th Nov 2022, 5:48 AM
Tibor Santa
Tibor Santa - avatar
0
It is for the hamstersimulator
26th Nov 2022, 7:01 AM
fff ggg
fff ggg - avatar