Home Answers Viewqa Java-Beginners Collatz Conjecture Program?

 
 


Allaa S
Collatz Conjecture Program?
0 Answer(s)      a year and 5 months ago
Posted in : Java Beginners

import java.util.Scanner;

public class Collatz{
    static Scanner scanner=new Scanner(System.in);
    public static void main(String[] args){
        System.out.println("Enter Positive Integer: ");
        int num=scanner.nextInt();
            while(num>1){
            if (num%2==0){
         num/=2;
         System.out.print(num+" ");
            }
            else{
            num=(num*3)+1;
            System.out.print(num+" ");
            }
        }
    }
}

How do i accumulate the sequence for each numbern in a Vector, by defining

public static Vector<Integer> sequence(int n)

And defining

public static int length(int n){
return sequence(n).size()-1;
}

Also how do i make f and length static functions?

View Answers









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.