1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #694 (The Collatz Sequence)
*
* @author David Leib
* @author Julius Tschannerl
* @version 1.0, 04/21/2009
*
* Status : Accepted
* Runtime: 2.380
*/

//package Collatz;

import java.util.Scanner;

public class Main {

private static int collatzCount = 0;

private static void nextCollatz(long i, int l)
{
collatzCount++;
if (i > l){
collatzCount--;
return;
}
if (i == 1)
return;
if (i%2 == 0)
nextCollatz(i/2, l);
else
nextCollatz(3*i+1, l);
}

public static void main(String... args)
{
int testCount = 0;
long init;
int limit;

Scanner sc = new Scanner (System.in);
init = (long)sc.nextInt();
limit = sc.nextInt();

while (!(init == -1 && limit == -1))
{
testCount++;
collatzCount = 0;
nextCollatz(init, limit);
System.out.printf("Case %d: A = %d, limit = %d, number of terms = %d\n", testCount, init, limit, collatzCount);
init = (long)sc.nextInt();
limit = sc.nextInt();
}
}
}

2.


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem: The Collatz Sequence (694)
* @author Christian Mitterreiter
* @author Rolf Luigs
* @version 1.0, 04/01/2009
* Status : Accepted
* Runtime: 1.000
*/

import java.util.Scanner;

public class Main {

public static int Collatz(long input, long max) {
int count = 1;

while(input!=1) {
if(input%2==0) {
input=input/2;
count++;
}
else {
input=3*input+1;
if(input>max) break;
count ++;
}
}
return count;
}


public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

long[] input = new long[40000];
input[0]=0;
int k=1;

while (input[k-1]!=-1 && input[k]!=-1) {
input[k]=scanner.nextInt();
k++;
}

int d = 0;
int i = 1;

while(input[i]!=-1) {
d++;
System.out.println("Case " + d + ": " + "A = " + input[i] + ", " + "limit = " + input[i+1] + ", number of terms = " + Collatz(input[i], input[i+1]));
i+=2;
}
}
}