java - non-static method towersOfHanoi(int, int, int, int) cannot be referenced from a static context? -


when compile tester, says in line 9:

non-static method towersofhanoi(int, int, int, int) cannot referenced static context

why cant reach towersofhanoi method?

i provided 2 classes below.

import java.io.*; import java.util.*; public class tester {     public static void main(string args[])     {         scanner swag = new scanner(system.in);         int yolo = swag.nextint();         towersofhanoi.towersofhanoi(yolo,1,3,2);     } } public class towersofhanoi {     public void towersofhanoi (int n, int from, int to, int spare)     {         if(n== 1)          {             moveone(from, to);         }         else          {             towersofhanoi(n-1, from, spare, to);             moveone(from, to);             towersofhanoi(n-1, spare, to, from);         }     }        private void moveone(int from, int to)     {         system.out.println(from + " ---> " + to);     } } 

problem line

towersofhanoi.towersofhanoi(yolo,1,3,2); 

either create object of towersofhanoi , invoke method on or declare method towersofhanoi.towersofhanoi static.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -