Stair-climbing puzzle: Difference between revisions
Content deleted Content added
→{{header|J}}: shorten explicit |
Added Java |
||
Line 182: | Line 182: | ||
+/\ step_up '' NB. another example |
+/\ step_up '' NB. another example |
||
_1 _2 _3 _2 _3 _2 _1 _2 _3 _4 _3 _2 _3 _2 _3 _2 _3 _2 _1 _2 _1 _2 _1 0 1</lang> |
_1 _2 _3 _2 _3 _2 _1 _2 _3 _4 _3 _2 _3 _2 _3 _2 _3 _2 _1 _2 _1 _2 _1 0 1</lang> |
||
=={{header|Java}}== |
|||
{{trans|C++}} |
|||
<lang java>public void stepUp() { |
|||
while (!step()) stepUp(); |
|||
}</lang> |
|||
The following uses a variable and is a bit longer, but avoids a possible stack overflow: |
|||
<lang cpp>public void stepUp(){ |
|||
for (int i = 0; i < 1; step() ? ++i : --i); |
|||
}</lang> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |