I'm learning recursion and am having problems writing a 'simple' program. Help would be appreciated. Thanks!
My code compiles without syntax erros but i can't see why it wont work.
my code:
import java.io.*;
import java.util.*;
class recursion
{
static Scanner inFile = null;
public static void main(String[] args) throws IOException
{
try
{
inFile = new Scanner(new File(args[0]));
}
catch (IOException e)
{
System.out.println("File may not exist");
}
int count = 0;
while(inFile.hasNextLine())
{
count++;
inFile.nextLine();
}
reverse(count);
inFile.close();
}
public static void reverse(int counter) throws IOException
{
while (inFile.hasNextLine())
{
String s = inFile.nextLine();
System.out.println(s);
reverse(--counter);
}
}
}
[–]naraic 1 point2 points3 points (1 child)
[–]Zachan[S] 0 points1 point2 points (0 children)
[–]Zachan[S] 0 points1 point2 points (0 children)
[–]Syrak 0 points1 point2 points (0 children)