我需要从接收字符串变量的构造函数中验证日期 mm/dd。我尝试了几种方法都没有运气。最后我尝试将字符串转换为 ascii 并以这种方式验证,但也不起作用:
public Dated(String dateStr)
{
this.dateStr = dateStr;
for (int i = 0; i < dateStr.length(); i++)
{
char c = dateStr.charAt(i);
asciiValues = (int) c; // change each string character to ASCII value
}
}
public void display()
{
System.out.println(asciiValues);
}