Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Collatz Conjecture Program?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Allaa S
Collatz Conjecture Program?
0 Answer(s)      3 years and a month 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?


Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com