-2

I am using an if statement to do a set of commands when an INT (which in this case is a number of a month like 02) is equal to a STRING (which is a date fully written out like so --> 02/14/1998) the fully written out dates are in a file

So I am asking the user to type in a date and a month (INTS) and compare that to the fully written out dates in the file and when the month is the month of the fully written out date and same w/ the year do a set of calculations.

    int userTypedMonth, userTypedYear
    string fileDate 
    if(userTypedMonth == fileDate && userTypedYear == fileDate){
          5+5=10
    } 

I know this is the wrong syntax of code but i wanted to show how Im trying to explain it.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Matthew
  • 5
  • 5

1 Answers1

0

You can fileDate.split("/") to split the fileDate into a String[] where index 0 is the month ("02"), index 1 is the day ("14"), and index 2 is the ("1998"). Then you could compare using userTypedMonth.equals(fileDateArray[0]) and userTypedYear.equals(fileDateArray[2]), assuming the userTypedMonth/Year were Strings instead of ints. If they are ints, use String.valueOf(userTypedMonth/Year) to compare.

Ashley Tan
  • 11
  • 4