/Collatz_conjecture

Java implementation using recursion.

Primary LanguageJava

Collatz Conjecture Sequence Generator

Overview

This Java program generates a sequence based on the Collatz conjecture, also known as the Syracuse suite. The Collatz conjecture is a sequence defined for positive integers, where each term in the sequence is obtained from the previous term according to certain rules.

Instructions

  1. Clone Repository:

    • Clone this repository to your local machine using the following command:
      git clone [repository_url]
  2. Compile the Code:

    • Ensure you have Java installed on your machine.
    • Navigate to the project directory in the terminal.
    • Compile the code using the following command:
      javac Main.java
  3. Run the Program:

    • Run the compiled program with the following command:
      java Main
    • Enter a positive integer when prompted.
  4. View Collatz Sequence:

    • The program will print the generated Collatz sequence for the entered number.

Code Explanation

  • The CollatzConjecture class contains the recursive method seqGenerate, which generates the Collatz sequence for a given positive integer.
  • The Main class is responsible for taking user input, creating an instance of CollatzConjecture, and displaying the generated sequence.

Example Usage

Enter a positive integer: 10
10 5 16 8 4 2 1

Note

  • Ensure that you enter a positive integer as input.
  • The program will print each term in the Collatz sequence until it reaches 1.

Feel free to explore and modify the code as needed! If you have any questions or improvements, please don't hesitate to reach out.