0
I am doing a URI (online Judge) exercise but is showing "Compilation error" due to error:
Main.java:8: error: non-static variable this cannot be referenced from a Static context Interfacetext i = new Interfacetext(); ^ 1 error
Follows the code:
import java.util.Scanner;
import java.io.IOException;
public class Main
{
public static void main(String[] args) throws IOException
{
InterfaceTexto i = new InterfaceTexto();
i.executar();
}
class InterfaceTexto
{
private Scanner entrada;
private Fibonacci fibonacci;
private int n;
private int t;
public InterfaceTexto()
{
entrada = new Scanner(System.in);
fibonacci = new Fibonacci();
}
public void executar()
{
t = entrada.nextInt();
for(int i = 0; i < t; i++)
{
fibonacci();
}
}
public void fibonacci()
{
n = entrada.nextInt();
System.out.printf("Fib(%d) = %d\n", n, fibonacci.numeroFibonacci(n));
}
}
class Fibonacci
{
private int[] fib;
private int n;
private static final int TAM = 61;
public Fibonacci()
{
fib = new int[TAM];
fib[0] = 0;
fib[1] = 1;
for (int i = 2; i < TAM; i++)
fib[i] = fib[i-1] + fib[i-2];
}
public int numeroFibonacci(int n)
{
int numero = fib[n];
return numero;
}
}
}