Advertisement
binibiningtinamoran

UlamHypothesis

Oct 10th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. public class Ulam {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         int num, print; // declare variable to store results
  6.         for (num = 1; num <= 25; num++) { // initialize for loop
  7.             print = num; // initialize results to 1, which is the value of "i"
  8.  
  9.             System.out.printf("\n%,d: ", print);
  10.  
  11.            do {
  12.                 if (print % 2 == 0) { // check if number is even
  13.                     print /= 2;
  14.                 } else { // if odd
  15.                     print = (print * 3) + 1;
  16.                 }
  17.                 System.out.printf("%,d ", print); // append number on the same line
  18.             } while (print != 1);
  19.             System.out.println(); // PRINTS AN EMPTY SPACE
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement