
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?
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.