The+Collatz+Sequence

Source Code code format="java5"

import java.util.Scanner;

public class CollatzSequence { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int c = 0; while(true) { int A = scan.nextInt;// �ʱⰪ int L = scan.nextInt; // �ִ밪 if(A == -1 || L == -1) { System.exit(0); }   int a = A;    int t = 1;// ��� Ƚ�� while(true) { if(a == 1) { break; }   // ¦���̸� ������ ������.    if((a & 0x01) == 0) { a = a / 2; }   // Ȧ���̸� 3���ϰ� 1���Ѵ�. else { a = 3 * a + 1; // �ִ밪���� ū�� üũ�Ѵ�. if(a > L) { break; }   }    t++; }   c++; System.out.print("Case " + c); System.out.print(": A = " + A); System.out.print(", limit = " + L); System.out.println(", number of terms = " + t); }   }    }

code