-1

I am in an intro to Java class and we have to make a numerology program. i have everything except the data validation done. We have to validate that the date put in was put correctly, including the forward slash. I tried using

    if(slash1 !< /)
    continue;

as it is in a while statement to make the whole thing repeat if something is incorrect. It always tells me that using a forward slash is invalid. Could someone point me in the direction of how to solve this?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • 1
    Could you show a bit more of your code? - it isn't quite clear what you are trying to do. Also `!<` is not a valid operator in Java, only `!=`. – DNA Oct 15 '12 at 22:14

1 Answers1

5

It's a little difficult to help until you post a bit more code and example data - what you have posted isn't valid Java...

You have !<, which is not a valid operator in Java, only !=.

You also have a plain / in the code, which is not legal Java - you'd have to quote it "/" or '/' to make it a legal String or char literal.

If you want to compare something against a String such as "/", you need to use .equals() or .contains() or similar methods. Do not try to compare Strings using == or != or you will get confusing results.

A powerful way to validate string patterns is to use Regular Expressions - see the Java tutorial on this topic.

Another way (for dates) is to define a SimpleDateFormat for your desired pattern.

Hope that helps...

Community
  • 1
  • 1
DNA
  • 42,007
  • 12
  • 107
  • 146
  • Thanks for the info. I did intend to type " != ". You answered my question. I just needed to make the / into a legal char. I would have copied my entire code over but unfortunately my school has copying to and from my Java program locked. – MapexDrummer93 Oct 16 '12 at 17:42