Syracuse's conjecture - Java Language Basics

Java examples for Language Basics:do while

Description

Syracuse's conjecture

Demo Code

public class Main {
  public static void main(String[] args) {
    int n = 13;//from   ww w .  j ava2s  . c o m
    do {
      if ((n % 2) == 0)
        n /= 2; // divide by 2
      else
        n = 3 * n + 1;
    } while (n > 1);
    System.out.println(n);
  }
}

Result


Related Tutorials