  /*
      This program prints out a 3N+1 sequence
      starting from a positive integer specified
      by the user.  It also counts the number
      of terms in the sequence, and prints out
      that number.   
  */

public class ThreeN {

   public static void main(String[] args) {                

     int N;       // for computing terms in the sequence
     int counter; // for counting the terms

     TextIO.put("Enter a positive integer: ");
     N = TextIO.getlnInt();

     counter = 0;
     while (N > 1) {
         if (N % 2 == 0)
            N = N / 2;
         else
            N = 3 * N + 1;
         TextIO.putln(N);
         counter = counter + 1;
     }

     System.out.println("There were " + counter +
                              " terms in the sequence.");

   }  // end of main()

}  // end of class ThreeN
