1

My current code is:

System.out.println(DATA_DIV);
System.out.println("Enter the Postal Code:");
postalCode = uIn.next();
postalCode = postalCode.toUpperCase();

what is the easiest and quickest way to check that every odd character is a letter and that every even character is a digit Example M3H4P3

Nick is tired
  • 6,860
  • 20
  • 39
  • 51
  • 2
    Well, the "simple" solution would probably use a regular expression of some kind. Really basically, something like `^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]`, but I'm sure there's some nice neat with to do repeating patterns – MadProgrammer Dec 15 '21 at 01:29
  • 2
    Or `^(?:[a-zA-Z][0-9]){3}` for the pattern repeated 3 times (after the initial match). But, I suspect that that's not what your instructor is going to be looking for, so you're going to need to setup a loop and one or more flags and test each character – MadProgrammer Dec 15 '21 at 01:33

0 Answers0