class Eksempler{ public static void main(String[] args){ final int TALL = 3; int tall = TALL; // Problemet v?rt: // Tell ned fra 3 til og med 1 // Tell ned vanlig /* while (tall != 0){ tall = tellNed(tall); } */ // Tell ned rekursivt tellNedRekursivt(TALL); // Tell opp rekursivt tellOppRekursivt(TALL); } public static int tellNed(int tall){ System.out.println("teller ned: " + tall); vent(1000); return tall - 1; } public static void tellNedRekursivt(int tall){ if (tall <= 0){ return; } System.out.println("teller ned rekursivt: " + tall); vent(1000); tellNedRekursivt(tall - 1); } public static void tellOppRekursivt(int tall){ if (tall <= 0){ return; } tellOppRekursivt(tall - 1); vent(1000); System.out.println("teller opp rekursivt: " + tall); } // Hjelpemetode public static void vent(int tid){ try{ Thread.sleep(tid); } catch (InterruptedException e){ System.out.println(e); } } }