Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int num;
- int numberofsteps = 0;
- System.out.println("Starting number:");
- num = keyboard.nextInt();
- do {
- numberofsteps=numberofsteps+1;
- System.out.println(num + " ");
- if ((num % 2) != 0)
- num = (3 * num) + 1;
- else
- num = num / 2;
- }
- while (num != 1) ;
- System.out.println(num);
- System.out.println("Terminated after " + numberofsteps + " steps.");
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement