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.
-
Clone Repository:
- Clone this repository to your local machine using the following command:
git clone [repository_url]
- Clone this repository to your local machine using the following command:
-
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
-
Run the Program:
- Run the compiled program with the following command:
java Main
- Enter a positive integer when prompted.
- Run the compiled program with the following command:
-
View Collatz Sequence:
- The program will print the generated Collatz sequence for the entered number.
- The
CollatzConjecture
class contains the recursive methodseqGenerate
, which generates the Collatz sequence for a given positive integer. - The
Main
class is responsible for taking user input, creating an instance ofCollatzConjecture
, and displaying the generated sequence.
Enter a positive integer: 10
10 5 16 8 4 2 1
- 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.