/**
* Created by abdul on 10/17/2016.
*/
import java.util.Scanner;
public class CollatzSequence {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter Cases: ");
int cases = in.nextInt();
int count = 0;
for (int i = 0; i <= cases; i++) {
int a = in.nextInt();
do {
if (a % 2 == 1) {
count++;
break;
} else if (a % 2 == 0){
a = a / 2;
a = a;
count++;
} else {
a = 3 * (a + 1);
a = a;
count++;
}
}while (a != 1) ;
} System.out.println(count);
}
}
this is not homework this is from code abbey http://www.codeabbey.com/index/task_view/collatz-sequence X is the initial number For example if X is even (i.e. X modulo 2 = 0) then Xnext = X / 2 else Xnext = 3 * X + 1 When x = 15 It takes 17 times for the sequence for it to reach 1. Please help me what I am doing wrong my loop will not even give an output anymore and before that wouldn't stop adding number