if condition always returns true (Java)

user3648416

I am trying to implement a date system that inevitably displays tomorrows day, month and year.

The problem I am having is that the one of the if statements always returns true, and the ones after this one always return false.

Here is part of my code:

public class dateVerification {

    int tomorrowDay = 0;
    int tomorrowMonth = 0;
    int tomorrowYear = 0;
    int day = 0;
    int month = 0;
    int year = 0;

    public void date() {

        Scanner myScanner = new Scanner(System.in);
        System.out.println("Enter the day");
        day = myScanner.nextInt();
        System.out.println("Enter the month");
        month = myScanner.nextInt();
        System.out.println("Enter the year");
        year = myScanner.nextInt();

        switch (month) {
            case 1:
                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10) {
                    if (day < 31) {
                        tomorrowDay = day + 1;
                    } else {
                        tomorrowDay = 1;
                        tomorrowMonth = month + 1;
                    }
                }
                break;

The line that is returning true is:

 if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10)

And everything else is returning false, i.e. my case 2 statement

if (month == 4 || month == 6 || month == 9 || month == 11)

Can anybody shed some light on this?

Gabriele Mariotti

You are testing the month field.

In case 1 the month is always 1.

 switch (month) {
            case 1:  //mount = 1 !!
                if (month == 1 ||...
     //
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why a condition that contains a pointer always returns true?

From Dev

if condition always evaluating true

From Dev

Term for an if condition that is always true

From Dev

dbHasCompleted always returns TRUE

From Dev

HasFlag always returns True

From Dev

function always returns true

From Dev

HasFlag always returns True

From Dev

If always returns true

From Dev

If returns always true

From Dev

condition always returns false

From Dev

javascript form validation always returns true even when condition matches and should returns false

From Dev

Intellij Idea hint: Condition is always false - can that be true here? (Java)

From Java

Built-in Java 8 predicate that always returns true?

From Dev

Java - remove method in Vector class always returns True

From Dev

Why is this PHP if condition always true?

From Dev

Why is this PHP if condition always true?

From Dev

awk condition always TRUE in a loop

From Dev

Bash Script if condition is always true

From Dev

Angular 2 - Custom validator always returns true, even when condition is false

From Dev

QSqlDatabase::open() always returns true

From Dev

strpos returns true always in php

From Dev

in_array() always returns TRUE

From Dev

Jquery inArray always returns true

From Dev

DataAnnotations tryvalidateobject always returns true

From Dev

Passport isAuthenticated() always returns TRUE

From Dev

'else if' statement always returns true

From Dev

Eloquent IF clause - always returns true

From Dev

comparing character always returns true

From Dev

strpos returns true always in php