Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is a simple program that computes the Collatz Conjecture of numbers input by the user
- //3-07-14
- import java.util.Scanner;
- public class CollatzConjecture
- {
- public static void main(String[] args)
- {
- System.out.println("Enter an integer to see its Collatz Conjecture,\nEnter 0 to exit:");
- Scanner scan = new Scanner(System.in);
- int num;
- while(true)
- {
- num = scan.nextInt();
- if(num==0) break;
- if(num%2==0) System.out.println("Collatz Conjecture of " + num + " = " + num/2);
- else System.out.println("Collatz Conjecture of " + num + " = " + (num*3+1));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement