public static void main ( String [] args ) {
    
	int counter;
	int max = 0;
	long t = 0;
	int fin =0;

	for ( int i=999999; i>0; i-- ) {
	    counter = 0;
	    t = i;
	    while ( t != 1 ) {
		if ( t%2 == 0 ) {
		    t = t / 2;
		}
		else {
		    t = t * 3 + 1;
		}
		counter++;
	    }
	    if ( counter > max ) {
		max = counter;
		fin = i;
	    }
	}

	System.out.println("final="+fin+", max="+max);

    }