且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何打印多行输出?并纠正我的递归方法?

更新时间:2023-12-04 11:53:28

Quote:

并更正我的递归方法?



更正代码是你的工作,调试器是帮助你的工具。

你可以***地创建任意复杂的代码,但是不要指望我们这样跟着你。

为什么你需要递归方法?


你想要的


prt1234(1)= 1

prt1234(2 )= 2

prt1234(3)= 3

prt1234(4)= 4

prt1234(5)= 5

问题是没有人会有想法看看递归方法来回答这个问题,因为有一个更简单的解决方案。



你的代码没有表现你期望的方式,或者你不明白为什么!



有一个几乎通用的解决方案:一步一步地在调试器上运行你的代码,检查变量。 />
调试器是她的e向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不知道您的代码应该做什么,它没有发现错误,只是通过向您展示正在发生的事情来帮助您。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。



a href =https://en.wikipedia.org/wiki/Debugger>调试器 - ***,免费的百科全书[ ^ ]



掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - *** [ ^ ]



http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]



这里的调试器只显示你的代码正在做什么,你的任务是与它应该做什么进行比较。


Correcting your code is your job, the debugger is the tool that will help you to.
You are free to create code as complicated as you want, but do not expect us to try to follow you this way.
Why do you need recursive methods ?

you want:
prt1234(1)=1
prt1234(2)=2
prt1234(3)=3
prt1234(4)=4
prt1234(5)=5
The problem is that nobody will have the idea to look at recursive method to answer this, because there is a much simpler solution.

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

a href="https://en.wikipedia.org/wiki/Debugger">Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - ***[^]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.