Created
January 31, 2014 23:53
-
-
Save russjr08/8745727 to your computer and use it in GitHub Desktop.
Project Euler Challenge 14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kronosad.practice.project_euler.challenge14; | |
import java.util.Scanner; | |
/** | |
* User: russjr08 | |
* Date: 1/31/14 | |
* Time: 5:46 PM | |
*/ | |
public class Main { | |
public static void main(String... args){ | |
Scanner input = new Scanner(System.in); | |
System.out.println("Enter a number: "); | |
int number = Integer.valueOf(input.nextLine()); | |
while(number != 1){ | |
if(isEven(number)){ | |
number = number / 2; | |
System.out.println(number); | |
}else{ | |
number = (number * 3) + 1; | |
System.out.println(number); | |
} | |
} | |
} | |
public static boolean isEven(int num){ | |
return num % 2 == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment