[英]Is this program recursive? If not, how do I make it recursive?
For my programming class, I was told to make a program that uses recursion. 在我的编程课上,我被告知要编写一个使用递归的程序。 I was confused and went to see my friend who was already in the class and he showed me this program.
我很困惑,去看我已经在上课的朋友,他给我看了这个程序。 I thought recursion had to use things like r1(x-1), etc. Is it actually recursive?
我以为递归必须使用r1(x-1)之类的东西,它实际上是递归的吗? If it's not, how do you make it recursive?
如果不是,您如何使其递归?
import java.util.*;
import java.io.*;
class ReverseFile
{
private static Scanner infile;
public static void main(String[] args) throws IOException
{
infile= new Scanner(new File("hw_1.txt"));
r1();
}
public static void r1()
{
String s;
if (infile.hasNextLine())
{
s = infile.nextLine();
r1();
System.out.println(s);
}
}
}
It is recursive as r1
calls itself. 当
r1
调用它时,它是递归的。 The fact that no arguments are passed to r1
doesn't matter. 没有参数传递给
r1
事实无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.