Skip to content

Instantly share code, notes, and snippets.

@russjr08
Created January 31, 2014 23:53
Show Gist options
  • Save russjr08/8745727 to your computer and use it in GitHub Desktop.
Save russjr08/8745727 to your computer and use it in GitHub Desktop.
Project Euler Challenge 14
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