Advertisement
Guest User

collatz conjecture

a guest
Mar 7th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. //This is a simple program that computes the Collatz Conjecture of numbers input by the user
  2. //3-07-14
  3. import java.util.Scanner;
  4. public class CollatzConjecture
  5. {
  6.    public static void main(String[] args)
  7.    {
  8.       System.out.println("Enter an integer to see its Collatz Conjecture,\nEnter 0 to exit:");
  9.       Scanner scan = new Scanner(System.in);
  10.       int num;
  11.       while(true)
  12.       {
  13.          num = scan.nextInt();
  14.          if(num==0)     break;
  15.          if(num%2==0)   System.out.println("Collatz Conjecture of " + num + " = " + num/2);
  16.          else           System.out.println("Collatz Conjecture of " + num + " = " + (num*3+1));
  17.       }
  18.    }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement