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