Advertisement
Blonk

Untitled

Dec 9th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.     public static void main(String[] args){
  4.         Scanner keyboard = new Scanner(System.in);
  5.         System.out.print("Starting number: ");
  6.         int start = keyboard.nextInt();
  7.         int count = 0;
  8.         int max = 0;
  9.         max = start;
  10.         System.out.print(start + "  ");
  11.         while(start != 1){
  12.             if(start % 2 == 0){
  13.                 start = start / 2;
  14.             }else{
  15.                 start= 3 * start + 1;
  16.             }
  17.             System.out.print(start + "  " );
  18.             count++;
  19.             if( start > max ){
  20.                 max = start;
  21.             }
  22.  
  23.         }
  24.         System.out.println();
  25.         System.out.println();
  26.         System.out.println("The largest value was " + max + ".");
  27.         System.out.println("Terminated after " + count + " steps.");
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement