package com.codegym.task.task04.task0426;
/*
Labels and numbers
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String sAge = reader.readLine();
int number = Integer.parseInt(sAge);
if (number == 0){
System.out.println("Zero");
}
else if (isPositive(number) && isOdd(number)){
System.out.println("Positive odd number");
}
else if (!(isPositive(number)) && (isOdd(number))) {
System.out.println("Negative odd number");
}
else if (isPositive(number) && (!isOdd(number))) {
System.out.println("Positive even number");
}
else if ((!isPositive(number) && (!isOdd(number)))) {
System.out.println("Negative even number");
}
}
public static boolean isOdd (int number){
int mod = number % 2;
mod = Math.abs(mod);
if (mod == 1) {
return true;
}
else {
return false;
}
}
public static boolean isPositive (int number){
if (number > 0) {
return true;
}
else {
return false;
}
}
}
Is this good solution?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Online Learner
25 July 2019, 13:11
yes but you can also do it in some lesss code
like you don't need to create isPositive or isOdd method
0
Lukas Smetana
25 July 2019, 15:29
Could you tell me how?
0
Dmitriy Bursa
25 July 2019, 19:35
isOdd = (Math.abs(number % 2) == 1)
isPositive = (number > 0)
maybe it's 0