Results 1 to 2 of 2
  1. #1
    fouzimedfouni is offline Member
    Join Date
    Feb 2016
    Posts
    1
    Rep Power
    0

    Exclamation why if doesn't evaluate correctly?

    hello I was trying to evaluate something for my assignment and it doesn't seem to work right
    it keeps giving me the result of ELSE statement instead of the result in IF statement when I enter a negative number or out of range numbers
    can you check that for me guys! thank you in advance

    Java Code:
    import java.util.*; // Impport the scanner
    public class Date
    {
        public static void main(String[] args)
      {
    	// Declaring variables
    	int inputYear;
    	int inputMonth;
    	int inputDay;
    	String legal = "You've entered good Date ++++++++++++++++++++:)";
    	String illegal = "You've entered BAD Date----------------------!! ";
    
    
        // Prompting the user
        System.out.print("Please enter a month (1-12) and day (1-31) and year (1-4000):   "  );
    
    	//Using scanner class for the input
        Scanner kb = new Scanner(System.in);
        inputMonth = kb.nextInt();
        inputDay = kb.nextInt();
        inputYear = kb.nextInt();
    
    
    
        System.out.print(" \n\n");
    
    
    	// A statement to be used as a condition for the user to  insert something  make sense(legal)
    	if((inputMonth < 0 && inputMonth > 12) && (inputDay < 0 && inputDay > 31) && (inputYear < 0 && inputYear > 4000))
    		System.out.println(illegal);
           else
                    System.out.println(legal);
    
        }
    }
    Last edited by JosAH; 03-01-2016 at 08:19 AM. Reason: removed the preposterous large font and color tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: why if doesn't evaluate correctly?

    Tell me about a number less than zero and greater than twelve ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Evaluate Formula : Row()
    By YannickL in forum Apache POI
    Replies: 2
    Last Post: 06-03-2014, 03:03 PM
  2. Why doesn't this time get parsed correctly?
    By jojo in forum New To Java
    Replies: 16
    Last Post: 04-20-2011, 03:35 PM
  3. ImageIO doesn't correctly read some standard JPG Files
    By francojava1 in forum Advanced Java
    Replies: 2
    Last Post: 10-18-2010, 04:33 PM
  4. Why doesn't my program function correctly?
    By robertbob in forum New To Java
    Replies: 7
    Last Post: 05-06-2010, 01:03 AM
  5. Evaluate a string expression
    By aparna_pall in forum New To Java
    Replies: 2
    Last Post: 04-10-2010, 03:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •