package com.codegym.task.task04.task0427;
/*
Describing numbers
*/
import com.sun.deploy.security.SelectableSecurityManager;
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
boolean even;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int number = Integer.parseInt(reader.readLine());
even = number % 2 == 0;
if (number >= 1 && number < 10 && even)
System.out.println("even single-digit number");
else if (number >= 1 && number < 10 && !even)
System.out.println("odd single-digit number");
if (number >= 10 && number < 100 && even)
System.out.print("even two-digit number");
else if (number >= 10 && number < 100 && !even)
System.out.println("odd two-digit number");
if (number >= 100 && number <= 999 && even)
System.out.print("odd three-digit number");
else if (number >= 100 && number <= 999 && !even)
System.out.println("odd three-digit number");
}
}
Seferi
Level 22
Why is !even always evaluates to true?
Archived
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Skynet
13 June 2020, 10:39
Where did you get that import from on line 8?
Try to do all 6 as different ifs, without else ifs.
Also, I believe for single-digit even and odd numbers, for example, the number check should be > 0 (at least that's what worked for me).
0
Guadalupe Gagnon
12 June 2020, 17:34
messaged you
+2
Brandon
12 June 2020, 17:00
I was hoping someone answered this, as I only have a guess myself.
My guess is that the if statements check each boolean in order. (number >=1, number <10, and !even). But because the only difference between the first "if statement", and the "else if statement" is your last check (even, or !even). If the checks make it to that last statement it has to be true, because you already checked the opposite in your first if statement.
So basically, forgetting the first 2 checks, because they are the exact same in both statements, you're left with:
if (even)
else if (!even)
if one isn't true, the other HAS to be.
0