SHARE
TWEET

Untitled

a guest Apr 2nd, 2014 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class SixtyTwoRemake {
  4.  
  5.         public static void main(String[] args) {
  6.        
  7.                 Scanner keyboard = new Scanner(System.in);
  8.                
  9.                 System.out.print("Starting Number: ");
  10.                 int n = keyboard.nextInt();
  11.                
  12.                 int stepsTaken = 0;
  13.                 int largestNumber = 0;
  14.                
  15.                 System.out.println();
  16.                 keyboard.close();
  17.                
  18.                 while ( n != 1 ){
  19.                         stepsTaken++;
  20.                         n = (n % 2 == 0) ? n / 2 : (n * 3) + 1;
  21.                         System.out.print(n + " ");
  22.                         if (n > largestNumber)
  23.                                 largestNumber = n;
  24.                         if (stepsTaken % 9 == 0)
  25.                                 System.out.print("\n");
  26.                 }
  27.                
  28.                 System.out.println();
  29.                 System.out.println("\nTerminated after " + stepsTaken + " steps.");
  30.                 System.out.println("The largest value was " + largestNumber + ".");
  31.                
  32.         }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top