dimanche 28 mai 2017

recursion and if-else satement

Am new to programming I am trying to use recursion and if-else statement only to print the 99 beers lyrics. here is my code.How can i make it better, to print the lyrics well.

public static void countdown(int n)
{   
    if (n== 0){
        System.out.println ("no beers");
    }
      else{
          System.out.println ("more beers");
          countdown(n-1);
        }
}

public static void countdownB (int x)
{   
    if (x==0){
        System.out.print ("");
    }
      else{
          System.out.print (x);
          countdownB (x-1);
        }
}



public static void main (String[] args)
{

   countdownB (3);
   countdown (3);

}

Aucun commentaire:

Enregistrer un commentaire