Created
November 13, 2014 07:13
-
-
Save giladoved/705e5efe5cede0f2c685 to your computer and use it in GitHub Desktop.
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
//Gilad Oved | |
import java.util.Scanner; | |
public class Watermelon4A { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
//get the weight of the watermelon | |
// this is the only input we get | |
int weight = in.nextInt(); | |
//defining a string of either yes or no depending on if the method returns true or false | |
String output = (isWatermelonEven(weight)) ? "YES" : "NO"; | |
//output the defined string of YES or NO | |
System.out.println(output); | |
} | |
//a method that returns true if the watermelon can be divided into even pieces and false if it can't | |
public static boolean isWatermelonEven(int w) { | |
//If the watermelon can evenly be divided by 2 (it is even) and the watermelon weight is greater than 2 then return true | |
if (w % 2 == 0 && w > 2) { | |
return true; | |
} | |
//otherwise return false | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment